From 7c5d3b636e108254d90ba5dccead90c4d26ef810 Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Fri, 21 Feb 2020 19:30:34 -0500 Subject: [PATCH] Template compare string_view overloads --- include/boost/static_string/static_string.hpp | 61 +++++++++++++------ 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/include/boost/static_string/static_string.hpp b/include/boost/static_string/static_string.hpp index b440c2e..980a17e 100644 --- a/include/boost/static_string/static_string.hpp +++ b/include/boost/static_string/static_string.hpp @@ -119,32 +119,32 @@ template using enable_if_viewable_t = typename enable_if_viewable::type; // Simplified check for if a type is an iterator -template +template struct is_iterator : std::false_type { }; -template +template struct is_iterator::value, void_t>::type> : std::true_type { }; -template +template struct is_iterator : std::true_type { }; -template +template struct is_input_iterator : std::false_type { }; -template +template struct is_input_iterator::value && std::is_convertible::iterator_category, std::input_iterator_tag>::value>::type> : std::true_type { }; -template +template struct is_forward_iterator : std::false_type { }; -template +template struct is_forward_iterator::value && std::is_convertible::iterator_category, std::forward_iterator_tag>::value>::type> @@ -763,7 +763,7 @@ public: Construct from a range of characters */ - template @@ -1067,8 +1067,8 @@ public: basic_static_string& assign(const T& t) { - string_view_type ss{t}; - return assign(ss.data(), ss.size()); + string_view_type sv = t; + return assign(sv.data(), sv.size()); } /** Replace the contents. @@ -2297,30 +2297,51 @@ public: /** Compare the string with another. - Compares this string to `s`. + Compares this string to `t` after converting `t` to `string_view_type`. + + This function participates in overload resolution if + `T` is convertible to `string_view_type` and `T` is not + convertible to `const_pointer`. */ + template +#endif + > BOOST_STATIC_STRING_CPP14_CONSTEXPR int compare( - string_view_type s) const noexcept + const T& t) const noexcept { + string_view_type sv = t; return detail::lexicographical_compare( - data(), size(), s.data(), s.size()); + data(), size(), t.data(), t.size()); } /** Compare the string with another. - Compares a `[pos1, pos1+count1)` substring of this string to `s`. If `count1 > size() - pos1` the substring is `[pos1, size())`. + Compares a `[pos1, pos1+count1)` substring of this string to `t` after converting it to + `string_view_type`. If `count1 > size() - pos1` + the substring is `[pos1, size())`. + + This function participates in overload resolution if + `T` is convertible to `string_view_type` and `T` is not + convertible to `const_pointer`. */ + template +#endif + > BOOST_STATIC_STRING_CPP14_CONSTEXPR int compare( size_type pos1, size_type count1, - string_view_type s) const + const T& t) const { return detail::lexicographical_compare( - subview(pos1, count1), s); + subview(pos1, count1), string_view_type(t)); } /** Compare the string with another. @@ -4793,7 +4814,7 @@ assign( } template -template +template BOOST_STATIC_STRING_CPP14_CONSTEXPR auto basic_static_string:: @@ -4841,7 +4862,7 @@ insert( } template -template +template BOOST_STATIC_STRING_CPP14_CONSTEXPR auto basic_static_string:: @@ -4886,7 +4907,7 @@ insert( } template -template +template BOOST_STATIC_STRING_CPP14_CONSTEXPR auto basic_static_string:: @@ -4975,7 +4996,7 @@ append( } template -template +template BOOST_STATIC_STRING_CPP14_CONSTEXPR auto basic_static_string::