diff --git a/include/boost/fixed_string/config.hpp b/include/boost/fixed_string/config.hpp index e3f9cac..fd4116c 100644 --- a/include/boost/fixed_string/config.hpp +++ b/include/boost/fixed_string/config.hpp @@ -13,18 +13,16 @@ // Are we dependent on Boost? #define BOOST_FIXED_STRING_USE_BOOST -// C++ version -#if __cplusplus >= 201703L -#define BOOST_FIXED_STRING_CPP17 -#elif __cplusplus >= 201402L -#define BOOST_FIXED_STRING_CPP14 -#else -#define BOOST_FIXED_STRING_CPP11 +// Can we have deduction guides? +#ifdef __cpp_deduction_guides +#define BOOST_FIXED_STRING_USE_DEDUCT #endif -// See if we can use `string_view` -#if defined(BOOST_FIXED_STRING_CPP17) || defined(BOOST_FIXED_STRING_USE_BOOST) -#define BOOST_FIXED_STRING_STRING_VIEW +// Can we use [[nodiscard]]? +#if __has_attribute(nodiscard) +#define BOOST_FIXED_STRING_NODISCARD [[nodiscard]] +#else +#define BOOST_FIXED_STRING_NODISCARD #endif #ifdef BOOST_FIXED_STRING_USE_BOOST @@ -34,47 +32,32 @@ #include #else #include -#ifdef BOOST_FIXED_STRING_CPP17 #include #endif -#endif // Boost and non-Boost versions of utilities #ifdef BOOST_FIXED_STRING_USE_BOOST #define BOOST_FIXED_STRING_THROW(ex) BOOST_THROW_EXCEPTION(ex) #define BOOST_FIXED_STRING_STATIC_ASSERT(cond, msg) BOOST_STATIC_ASSERT_MSG(cond, msg) #define BOOST_FIXED_STRING_ASSERT(cond) BOOST_ASSERT(cond) -#ifdef BOOST_NODISCARD -#define BOOST_FIXED_STRING_NODISCARD BOOST_NODISCARD -#else -#define BOOST_FIXED_STRING_NODISCARD -#endif #else #define BOOST_FIXED_STRING_THROW(ex) throw ex #define BOOST_FIXED_STRING_STATIC_ASSERT(cond, msg) static_assert(cond, msg) #define BOOST_FIXED_STRING_ASSERT(cond) assert(cond) -#ifdef BOOST_FIXED_STRING_CPP17 -#define BOOST_FIXED_STRING_NODISCARD [[nodiscard]] -#else -#define BOOST_FIXED_STRING_NODISCARD -#endif #endif namespace boost { namespace fixed_string { /// The type of `string_view` used by the library -#ifdef BOOST_FIXED_STRING_STRING_VIEW using string_view = #ifdef BOOST_FIXED_STRING_USE_BOOST boost::string_view; #else std::string_view; #endif -#endif /// The type of `basic_string_view` used by the library -#ifdef BOOST_FIXED_STRING_STRING_VIEW template using basic_string_view = #ifdef BOOST_FIXED_STRING_USE_BOOST @@ -82,7 +65,6 @@ using basic_string_view = #else std::basic_string_view; #endif -#endif } // fixed_string } // boost diff --git a/include/boost/fixed_string/detail/fixed_string.hpp b/include/boost/fixed_string/detail/fixed_string.hpp index 9442f7d..f5efac6 100644 --- a/include/boost/fixed_string/detail/fixed_string.hpp +++ b/include/boost/fixed_string/detail/fixed_string.hpp @@ -44,8 +44,6 @@ lexicographical_compare( return Traits::compare(s1, s2, n1); } - -#ifdef BOOST_FIXED_STRING_STRING_VIEW template inline int @@ -56,7 +54,6 @@ lexicographical_compare( return detail::lexicographical_compare< CharT, Traits>(s1.data(), s1.size(), s2, n2); } -#endif template inline @@ -69,7 +66,6 @@ lexicographical_compare( CharT, Traits>(s1.data(), s1.size(), s2, n2); } -#ifdef BOOST_FIXED_STRING_STRING_VIEW template inline int @@ -80,7 +76,6 @@ lexicographical_compare( return detail::lexicographical_compare( s1.data(), s1.size(), s2.data(), s2.size()); } -#endif template inline diff --git a/include/boost/fixed_string/fixed_string.hpp b/include/boost/fixed_string/fixed_string.hpp index 694d599..c400ca1 100644 --- a/include/boost/fixed_string/fixed_string.hpp +++ b/include/boost/fixed_string/fixed_string.hpp @@ -77,10 +77,8 @@ public: std::reverse_iterator; /// The type of `string_view` returned by the interface -#ifdef BOOST_FIXED_STRING_STRING_VIEW using string_view_type = string_view; -#endif //-------------------------------------------------------------------------- // @@ -160,11 +158,9 @@ public: /// Construct from a `string_view` -#ifdef BOOST_FIXED_STRING_STRING_VIEW explicit fixed_string( string_view_type sv); -#endif /** Construct from any object convertible to `string_view_type`. @@ -172,7 +168,6 @@ public: obtained by converting `t` to `string_view_type`, and used to construct the string. */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW template max_size()` */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW template #if GENERATING_DOCUMENTATION fixed_string& @@ -369,7 +360,6 @@ public: string_view_type ss{t}; return assign(ss.data(), ss.size()); } -#endif /** Replace the contents with a copy of the characters from `string_view_type{t}.substr(pos, count)` @@ -381,7 +371,6 @@ public: @throw std::length_error if `string_view_type{t}.substr(pos, count).size() > max_size()` */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW template #if GENERATING_DOCUMENTATION fixed_string& @@ -398,7 +387,6 @@ public: { return assign(string_view_type{t}.substr(pos, count)); } -#endif //-------------------------------------------------------------------------- // @@ -502,13 +490,11 @@ public: } /// Convert a static string to a `string_view_type` -#ifdef BOOST_FIXED_STRING_STRING_VIEW operator string_view_type() const noexcept { return basic_string_view< CharT, Traits>{data(), size()}; } -#endif //-------------------------------------------------------------------------- // @@ -724,7 +710,6 @@ public: @throw std::length_error if `size() + sv.size() > max_size()` @return `*this` */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW fixed_string& insert( size_type index, @@ -732,7 +717,6 @@ public: { return insert(index, sv.data(), sv.size()); } -#endif /** Inserts the string `sv.substr(index_str, count)` at the position `index` @@ -742,7 +726,6 @@ public: @throw std::length_error if `size() + sv.substr(index_str, count).size() > max_size()` @return `*this` */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW fixed_string& insert( size_type index, @@ -752,7 +735,6 @@ public: { return insert(index, sv.substr(index_str, count)); } -#endif /** Inserts character `ch` before the character (if any) pointed by `pos` @@ -829,7 +811,6 @@ public: @throw std::length_error if `size() + string_view{t}.substr(index_str, count).size() > max_size()` @return `*this` */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW template #if GENERATING_DOCUMENTATION fixed_string& @@ -844,7 +825,6 @@ public: insert( size_type index, T const& t); -#endif /** Inserts elements from `string_view{t}.substr(index_str, count)` at the position `index` @@ -857,7 +837,6 @@ public: @throw std::length_error if `size() + string_view{t}.substr(index_str, count).size() > max_size()` @return `*this` */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW template #if GENERATING_DOCUMENTATION fixed_string& @@ -872,7 +851,6 @@ public: T const& t, size_type index_str, size_type count = npos); -#endif /** Removes `min(count, size() - index)` characters starting at `index` @@ -942,14 +920,12 @@ public: @throw std::length_error if `size() + sv.size() > max_size()` @return `*this` */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW fixed_string& append( string_view_type sv) { return append(sv.data(), sv.size()); } -#endif /** Appends the contents of `sv.substr(pos, count)` @@ -959,7 +935,6 @@ public: @throw std::length_error if `size() + sv.substr(pos, count).size() > max_size()` @return `*this` */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW fixed_string& append( string_view_type sv, @@ -968,7 +943,6 @@ public: { return append(sv.substr(pos, count)); } -#endif /** Appends characters in the range `(s, s + count)` @@ -1047,7 +1021,6 @@ public: @throw std::length_error if `size() + string_view{t} > max_size()` @return `*this` */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW template #if GENERATING_DOCUMENTATION fixed_string& @@ -1064,7 +1037,6 @@ public: { return append(string_view{t}); } -#endif /** Appends characters from `string_view{t}.substr{pos, count}` @@ -1077,7 +1049,6 @@ public: @throw std::length_error if `size() + string_view{t}.substr(pos, count).size() > max_size()` @return `*this` */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW template #if GENERATING_DOCUMENTATION fixed_string& @@ -1096,7 +1067,6 @@ public: { return append(string_view{t}.substr(pos, count)); } -#endif template fixed_string& @@ -1156,7 +1126,6 @@ public: @throw std::length_error if `string_view_type{t}.size() > max_size()` */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW template #if GENERATING_DOCUMENTATION fixed_string& @@ -1171,7 +1140,6 @@ public: { return append(t); } -#endif template int @@ -1235,7 +1203,6 @@ public: substr(pos1, count1), s, count2); } -#ifdef BOOST_FIXED_STRING_STRING_VIEW int compare( string_view_type s) const @@ -1244,9 +1211,6 @@ public: &s_[0], n_, s.data(), s.size()); } -#endif - -#ifdef BOOST_FIXED_STRING_STRING_VIEW int compare( size_type pos1, @@ -1256,9 +1220,7 @@ public: return detail::lexicographical_compare( substr(pos1, count1), s); } -#endif -#ifdef BOOST_FIXED_STRING_STRING_VIEW template #if GENERATING_DOCUMENTATION int @@ -1278,9 +1240,8 @@ public: return compare(pos1, count1, string_view_type(t).substr(pos2, count2)); } -#endif - fixed_string + string_view_type substr( size_type pos = 0, size_type count = npos) const; @@ -1344,7 +1305,6 @@ public: return replace(pos1, n1, str.substr(pos2, n2)); } -#ifdef BOOST_FIXED_STRING_STRING_VIEW template #if GENERATING_DOCUMENTATION fixed_string& @@ -1362,12 +1322,9 @@ public: string_view_type sv = t; return replace(pos1, n1, sv.data(), sv.size()); } -#endif -#ifdef BOOST_FIXED_STRING_STRING_VIEW template -#if GENERATI - NG_DOCUMENTATION +#if GENERATING_DOCUMENTATION fixed_string& #else typename std::enable_if< @@ -1385,7 +1342,6 @@ public: string_view_type sv = t; return replace(pos1, n1, sv.substr(pos2, n2)); } -#endif fixed_string& replace( @@ -1419,7 +1375,6 @@ public: return replace(i1, i2, str.data(), str.size()); } -#ifdef BOOST_FIXED_STRING_STRING_VIEW template #if GENERATING_DOCUMENTATION fixed_string& @@ -1437,7 +1392,6 @@ public: string_view_type sv = t; return replace(i1 - begin(), i2 - i1, sv.data(), sv.size()); } -#endif fixed_string& replace( @@ -1506,7 +1460,6 @@ public: `T` is convertible to `string_view` and `T` is not convertible to `CharT const*`. */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW template #if GENERATING_DOCUMENTATION size_type @@ -1523,7 +1476,6 @@ public: string_view_type sv = t; return find(sv.data(), pos, sv.size()); } -#endif template size_type @@ -1571,7 +1523,6 @@ public: `T` is convertible to `string_view` and `T` is not convertible to `CharT const*`. */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW template #if GENERATING_DOCUMENTATION size_type @@ -1588,7 +1539,6 @@ public: string_view_type sv = t; return rfind(sv.data(), pos, sv.size()); } -#endif template size_type @@ -1635,7 +1585,6 @@ public: `T` is convertible to `string_view` and `T` is not convertible to `CharT const*`. */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW template #if GENERATING_DOCUMENTATION size_type @@ -1652,7 +1601,6 @@ public: string_view_type sv = t; return find_first_of(sv.data(), pos, sv.size()); } -#endif template size_type @@ -1699,7 +1647,6 @@ public: `T` is convertible to `string_view` and `T` is not convertible to `CharT const*`. */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW template #if GENERATING_DOCUMENTATION size_type @@ -1716,7 +1663,6 @@ public: string_view_type sv = t; return find_last_of(sv.data(), pos, sv.size()); } -#endif template size_type @@ -1763,7 +1709,6 @@ public: `T` is convertible to `string_view` and `T` is not convertible to `CharT const*`. */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW template #if GENERATING_DOCUMENTATION size_type @@ -1780,7 +1725,6 @@ public: string_view_type sv = t; return find_first_not_of(sv.data(), pos, sv.size()); } -#endif template size_type @@ -1827,7 +1771,6 @@ public: `T` is convertible to `string_view` and `T` is not convertible to `CharT const*`. */ -#ifdef BOOST_FIXED_STRING_STRING_VIEW template #if GENERATING_DOCUMENTATION size_type @@ -1844,7 +1787,6 @@ public: string_view_type sv = t; return find_last_not_of(sv.data(), pos, sv.size()); } -#endif template size_type @@ -1886,14 +1828,12 @@ public: return find_last_not_of(&c, pos, 1); } -#ifdef BOOST_FIXED_STRING_STRING_VIEW bool starts_with( string_view_type s) const noexcept { return starts_with(s.data()); } -#endif bool starts_with( @@ -1910,14 +1850,12 @@ public: return n_ >= len && !Traits::compare(s_, s, len); } -#ifdef BOOST_FIXED_STRING_STRING_VIEW bool ends_with( string_view_type s) const noexcept { return ends_with(s.data()); } -#endif bool ends_with( @@ -2253,10 +2191,7 @@ std::basic_ostream& operator<<(std::basic_ostream& os, fixed_string const& s) { - // for the non-trivial CharT - for (const CharT& c : s) - os << c; - return os; + return os << string_view(s); } //------------------------------------------------------------------------------ @@ -2291,7 +2226,7 @@ to_fixed_string(Integer x); // //------------------------------------------------------------------------------ -#ifdef BOOST_FIXED_STRING_CPP17 +#ifdef BOOST_FIXED_STRING_USE_DEDUCT template fixed_string(CharT(&)[N]) -> fixed_string>; diff --git a/include/boost/fixed_string/impl/fixed_string.hpp b/include/boost/fixed_string/impl/fixed_string.hpp index 99198f1..0cfb7ae 100644 --- a/include/boost/fixed_string/impl/fixed_string.hpp +++ b/include/boost/fixed_string/impl/fixed_string.hpp @@ -113,16 +113,13 @@ fixed_string(std::initializer_list init) assign(init.begin(), init.end()); } -#ifdef BOOST_FIXED_STRING_STRING_VIEW template fixed_string:: fixed_string(string_view_type sv) { assign(sv); } -#endif -#ifdef BOOST_FIXED_STRING_STRING_VIEW template template fixed_string:: @@ -130,7 +127,6 @@ fixed_string(T const& t, size_type pos, size_type n) { assign(t, pos, n); } -#endif //------------------------------------------------------------------------------ // @@ -393,7 +389,6 @@ insert( return begin() + index; } -#ifdef BOOST_FIXED_STRING_STRING_VIEW template template auto @@ -410,9 +405,7 @@ insert( { return insert(index, t, 0, npos); } -#endif -#ifdef BOOST_FIXED_STRING_STRING_VIEW template template auto @@ -433,7 +426,6 @@ insert( string_view_type(t).substr(index_str, count); return insert(index, s.data(), s.size()); } -#endif //------------------------------------------------------------------------------ @@ -515,7 +507,7 @@ template auto fixed_string:: substr(size_type pos, size_type count) const -> - fixed_string + string_view { if(pos > size()) BOOST_FIXED_STRING_THROW(std::out_of_range{