diff --git a/include/string_span.h b/include/string_span.h index b11dd9e..b681a5c 100644 --- a/include/string_span.h +++ b/include/string_span.h @@ -86,7 +86,7 @@ using wzstring = wchar_t*; // // Will fail-fast if sentinel cannot be found before max elements are examined. // -template +template span ensure_sentinel(T* seq, std::ptrdiff_t max = PTRDIFF_MAX) { auto cur = seq; @@ -101,7 +101,7 @@ span ensure_sentinel(T* seq, std::ptrdiff_t max = PTRDIFF_MAX) // Will fail fast if a null-terminator cannot be found before // the limit of size_type. // -template +template inline span ensure_z(T* const & sz, std::ptrdiff_t max = PTRDIFF_MAX) { return ensure_sentinel(sz, max); @@ -133,7 +133,7 @@ inline span ensure_z(const wchar_t* const& sz, std Ensures(sz[len] == 0); return{ sz, static_cast(len) }; } -template +template span ensure_z(T(&sz)[N]) { return ensure_z(&sz[0], static_cast(N)); } template @@ -168,7 +168,7 @@ inline span remove_z(const wchar_t* const& sz, std return{ sz, static_cast(len) }; } -template +template span remove_z(T(&sz)[N]) { return remove_z(&sz[0], static_cast(N)); @@ -203,7 +203,7 @@ namespace details // // Note that Extent is always single-dimension only // -template +template class basic_string_span { using value_type = CharT; @@ -237,7 +237,7 @@ public: {} // from nullptr and length - constexpr basic_string_span(nullptr_t ptr, size_type length) noexcept + constexpr basic_string_span(std::nullptr_t ptr, size_type length) noexcept : real(ptr, length) {} @@ -250,8 +250,8 @@ public: {} // from non-const pointer to const span - template::value>> - constexpr basic_string_span(std::remove_const_t*& ptr) noexcept + template, bool Enabled = std::is_const::value, typename Dummy = std::enable_if_t> + constexpr basic_string_span(ValueType*& ptr) noexcept : real(ensure_z(ptr)) {} @@ -306,29 +306,29 @@ public: template constexpr basic_string_span first() const noexcept { - return{ real.first() }; + return{ real.template first() }; } constexpr basic_string_span first(size_type count) const noexcept { - return{ real.first(count); } + return{ real.first(count) }; } template constexpr basic_string_span last() const noexcept { - return{ real.last() }; + return{ real.template last() }; } constexpr basic_string_span last(size_type count) const noexcept { - return{ real.last(count); } + return{ real.last(count) }; } template constexpr basic_string_span sub() const noexcept { - return{ real.sub() }; + return{ real.template sub() }; } constexpr basic_string_span sub(size_type offset, size_type count = dynamic_range) const noexcept @@ -442,7 +442,7 @@ using cwstring_span = basic_string_span; // #ifndef GSL_MSVC_HAS_TYPE_DEDUCTION_BUG -template +template std::basic_string::type> to_string(basic_string_span view) { return{ view.data(), static_cast(view.length()) }; @@ -472,7 +472,7 @@ inline std::wstring to_string(wstring_span<> view) #endif -template +template class basic_zstring_builder { public: @@ -509,24 +509,32 @@ template using wzstring_builder = basic_zstring_builder; } - -constexpr bool operator==(const gsl::cstring_span<>& one, const gsl::cstring_span<>& other) noexcept +/* +bool operator==(const gsl::cstring_span<>& one, const gsl::cstring_span<>& other) noexcept { return std::equal(one.begin(), one.end(), other.begin(), other.end()); } -constexpr bool operator==(const gsl::string_span<>& one, const gsl::string_span<>& other) noexcept +bool operator==(const gsl::cwstring_span<>& one, const gsl::cwstring_span<>& other) noexcept +{ + return std::equal(one.begin(), one.end(), other.begin(), other.end()); +} +*/ + + +template +bool operator==(const gsl::basic_string_span& one, const gsl::basic_string_span& other) noexcept { return std::equal(one.begin(), one.end(), other.begin(), other.end()); } - -// TODO: ca we make twmplate ops work? -//template -//constexpr bool operator==(const gsl::basic_string_span& one, const gsl::basic_string_span& other) noexcept -//{ -// return std::equal(one.begin(), one.end(), other.begin(), other.end()); -//} +/* +template , std::remove_cv_t>::value>> +constexpr bool operator==(const gsl::basic_string_span& one, const gsl::basic_string_span& other) noexcept +{ + return std::equal(one.begin(), one.end(), other.begin(), other.end()); +} +*/ /* template , std::remove_cv_t>::value>> constexpr bool operator==(const gsl::basic_string_span& one, const gsl::basic_string_span& other) noexcept diff --git a/tests/string_span_tests.cpp b/tests/string_span_tests.cpp index 08faaa8..90b7c3c 100644 --- a/tests/string_span_tests.cpp +++ b/tests/string_span_tests.cpp @@ -248,7 +248,7 @@ SUITE(string_span_tests) cstring_span<> sp2{ ptr, 3 }; // bad... but can't help there CHECK(sp1[1] == 'b'); - CHECK_THROW((sp1[2] == 'c'), fail_fast); + CHECK_THROW((void)(sp1[2] == 'c'), fail_fast); CHECK(sp2[1] == 'b'); //CHECK_THROW((sp1[2] == 'c'), fail_fast); // buffer overflow @@ -295,9 +295,12 @@ SUITE(string_span_tests) // from non-const ptr and length { + // does not compile with GCC (ISO standard does not allow converting string literals to char*) +#ifdef CONFIRM_COMPILATION_ERRORS char* ptr = "Hello"; cstring_span<> span{ ptr, 5 }; CHECK(span.length() == 5); +#endif } // from const string @@ -398,9 +401,12 @@ SUITE(string_span_tests) // from non-const ptr and length { + // does not compile with GCC (ISO standard does not allows converting string literals to char*) +#ifdef CONFIRM_COMPILATION_ERRORS char* ptr = "Hello"; string_span<> span{ ptr, 5 }; CHECK(span.length() == 5); +#endif } // from const string