diff --git a/include/gsl/string_span b/include/gsl/string_span index 506001f..938c71d 100644 --- a/include/gsl/string_span +++ b/include/gsl/string_span @@ -81,7 +81,7 @@ using u32zstring = basic_zstring; namespace details { template - std::size_t string_length(const CharT* str, std::size_t n) + constexpr std::size_t string_length(const CharT* str, std::size_t n) { if (str == nullptr || n == dynamic_extent) return 0; @@ -103,7 +103,7 @@ namespace details // Will fail-fast if sentinel cannot be found before max elements are examined. // template -span ensure_sentinel(T* seq, +constexpr span ensure_sentinel(T* seq, std::size_t max = static_cast(-1)) { Ensures(seq != nullptr); @@ -124,20 +124,20 @@ span ensure_sentinel(T* seq, // Will fail fast if a null-terminator cannot be found before the limit of size_type. // template -span ensure_z(CharT* const& sz, +constexpr span ensure_z(CharT* const& sz, std::size_t max = static_cast(-1)) { return ensure_sentinel(sz, max); } template -span ensure_z(CharT (&sz)[N]) +constexpr span ensure_z(CharT (&sz)[N]) { return ensure_z(&sz[0], N); } template -span::type, dynamic_extent> +constexpr span::type, dynamic_extent> ensure_z(Cont& cont) { return ensure_z(cont.data(), cont.size()); @@ -300,13 +300,13 @@ public: constexpr reverse_iterator rend() const noexcept { return span_.rend(); } private: - static impl_type remove_z(pointer const& sz, std::size_t max) + static constexpr impl_type remove_z(pointer const& sz, std::size_t max) { return impl_type(sz, details::string_length(sz, max)); } template - static impl_type remove_z(element_type (&sz)[N]) + static constexpr impl_type remove_z(element_type (&sz)[N]) { return remove_z(&sz[0], N); } @@ -343,7 +343,7 @@ using cu32string_span = basic_string_span; // template -std::basic_string::type> +constexpr std::basic_string::type> to_string(basic_string_span view) { return {view.data(), narrow_cast(view.length())}; @@ -351,13 +351,14 @@ to_string(basic_string_span view) template , typename Allocator = std::allocator, typename gCharT, std::size_t Extent> -std::basic_string to_basic_string(basic_string_span view) +constexpr std::basic_string +to_basic_string(basic_string_span view) { return {view.data(), narrow_cast(view.length())}; } template -basic_string_span::value> +constexpr basic_string_span::value> as_bytes(basic_string_span s) noexcept { GSL_SUPPRESS(type.1) // NO-FORMAT: attribute @@ -366,7 +367,7 @@ as_bytes(basic_string_span s) noexcept template ::value>> -basic_string_span::value> +constexpr basic_string_span::value> as_writable_bytes(basic_string_span s) noexcept { GSL_SUPPRESS(type.1) // NO-FORMAT: attribute