summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/string_view.h
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2016-01-15 19:18:29 +0100
committerJulian Andres Klode <jak@debian.org>2016-01-15 19:18:29 +0100
commitef6cc0e22a2933e0e36bc260179fdf0b86f9ac26 (patch)
treedd7e7db658d6babcb603b7fd714febc88aeaca84 /apt-pkg/contrib/string_view.h
parent3b4045fc31baf3aa580bd695695d579c30a481b8 (diff)
string_view: Drop constexpr constructor for standard compatibility
APT::StringView is supposed to be a temporary measure, until support for the standardized string_view is widely available. Introducing additional unstandardized features just makes porting to the standard version harder. The constexpr constructor also won't have any real effect on most systems, as the compiler will happily optimise the strlen() call away for constant strings. Gbp-Dch: ignore
Diffstat (limited to 'apt-pkg/contrib/string_view.h')
-rw-r--r--apt-pkg/contrib/string_view.h14
1 files changed, 4 insertions, 10 deletions
diff --git a/apt-pkg/contrib/string_view.h b/apt-pkg/contrib/string_view.h
index ea38224e8..d4ff80028 100644
--- a/apt-pkg/contrib/string_view.h
+++ b/apt-pkg/contrib/string_view.h
@@ -27,10 +27,6 @@ class StringView {
const char *data_;
size_t size_;
- // without this little stunt the "char const *" overload is always preferred
- // over char[], but if we got a char[] we can deduct the length at compile time
- #define APT_T_IS_CHARPOINTER template<class T, typename std::enable_if<std::is_pointer<T>{} && !std::is_array<T>{}>::type* = nullptr>
-
public:
static constexpr size_t npos = static_cast<size_t>(-1);
static_assert(APT::StringView::npos == std::string::npos, "npos values are different");
@@ -39,11 +35,10 @@ public:
constexpr StringView() : data_(""), size_(0) {}
constexpr StringView(const char *data, size_t size) : data_(data), size_(size) {}
- template<size_t N> constexpr StringView(char const (&data)[N]) : StringView(data, N-1) {}
- APT_T_IS_CHARPOINTER StringView(T data) : data_(data), size_(strlen(data)) {}
-
+ StringView(const char *data) : data_(data), size_(strlen(data)) {}
StringView(std::string const & str): data_(str.data()), size_(str.size()) {}
+
/* Viewers */
constexpr StringView substr(size_t pos, size_t n = npos) const {
return StringView(data_ + pos, n > (size_ - pos) ? (size_ - pos) : n);
@@ -119,8 +114,7 @@ public:
}
-template<size_t N> inline bool operator ==(char const (&other)[N], APT::StringView that) { return that.operator==(other); }
-APT_T_IS_CHARPOINTER inline bool operator ==(T other, APT::StringView that) { return that.operator==(other); }
+inline bool operator ==(const char *other, APT::StringView that);
+inline bool operator ==(const char *other, APT::StringView that) { return that.operator==(other); }
-#undef APT_T_IS_CHARPOINTER
#endif