From 47c025793349ca394e8410207bf3414834826a1f Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Fri, 21 Feb 2020 20:01:22 -0500 Subject: [PATCH] Remove unused overloads, eliminate use of subview --- include/boost/static_string/static_string.hpp | 130 +++++------------- 1 file changed, 37 insertions(+), 93 deletions(-) diff --git a/include/boost/static_string/static_string.hpp b/include/boost/static_string/static_string.hpp index 980a17e..4bfdf9f 100644 --- a/include/boost/static_string/static_string.hpp +++ b/include/boost/static_string/static_string.hpp @@ -321,31 +321,6 @@ lexicographical_compare( return Traits::compare(s1, s2, n1); } -template -BOOST_STATIC_STRING_CPP14_CONSTEXPR -inline -int -lexicographical_compare( - basic_string_view s1, - const CharT* s2, - std::size_t n2) noexcept -{ - return detail::lexicographical_compare< - CharT, Traits>(s1.data(), s1.size(), s2, n2); -} - -template -BOOST_STATIC_STRING_CPP14_CONSTEXPR -inline -int -lexicographical_compare( - basic_string_view s1, - basic_string_view s2) noexcept -{ - return detail::lexicographical_compare( - s1.data(), s1.size(), s2.data(), s2.size()); -} - template inline char* @@ -758,7 +733,7 @@ public: BOOST_STATIC_STRING_CPP14_CONSTEXPR basic_static_string(const_pointer s); - // KRYSTIAN TODO: we can use a better algorithm if this is a forward iterator + /** Construct a `basic_static_string`. Construct from a range of characters @@ -775,6 +750,7 @@ public: InputIterator first, InputIterator last) { + // KRYSTIAN TODO: we can use a better algorithm if this is a forward iterator assign(first, last); } @@ -807,19 +783,23 @@ public: BOOST_STATIC_STRING_CPP14_CONSTEXPR basic_static_string(std::initializer_list init) { - assign(init.begin(), init.end()); + assign(init.begin(), init.size()); } - // KRYSTIAN TODO: this may need to be templated /** Construct a `basic_static_string`. - Construct from a `string_view_type` + Construct from a object convertible to `string_view_type` */ + template +#endif + > explicit BOOST_STATIC_STRING_CPP14_CONSTEXPR - basic_static_string(string_view_type sv) + basic_static_string(const T& t) { - assign(sv); + assign(t); } /** Construct a `basic_static_string`. @@ -988,7 +968,10 @@ public: assign( const basic_static_string& s, size_type pos, - size_type count = npos); + size_type count = npos) + { + return assign(s.data() + pos, s.capped_length(pos, count)); + } /** Replace the contents. @@ -1261,7 +1244,7 @@ public: iterator end() noexcept { - return &data()[size()]; + return data() + size(); } /// Returns an iterator to the end. @@ -1269,7 +1252,7 @@ public: const_iterator end() const noexcept { - return &data()[size()]; + return data() + size(); } /// Returns an iterator to the end. @@ -1277,7 +1260,7 @@ public: const_iterator cend() const noexcept { - return &data()[size()]; + return data() + size(); } /// Returns a reverse iterator to the beginning. @@ -2227,7 +2210,7 @@ public: const basic_static_string& s) const { return detail::lexicographical_compare( - subview(pos1, count1), s.data(), s.size()); + data() + pos1, capped_length(pos1, count1), s.data(), s.size()); } /** Compare the string with another. @@ -2246,8 +2229,9 @@ public: size_type pos2, size_type count2 = npos) const { - return detail::lexicographical_compare( - subview(pos1, count1), s.subview(pos2, count2)); + return detail::lexicographical_compare( + data() + pos1, capped_length(pos1, count1), + s.data() + pos2, s.capped_length(pos2, count2)); } /** Compare the string with another. @@ -2276,7 +2260,7 @@ public: const_pointer s) const { return detail::lexicographical_compare( - subview(pos1, count1), s, traits_type::length(s)); + data() + pos1, capped_length(pos1, count1), s, traits_type::length(s)); } /** Compare the string with another. @@ -2292,7 +2276,7 @@ public: size_type count2) const { return detail::lexicographical_compare( - subview(pos1, count1), s, count2); + data() + pos1, capped_length(pos1, count1), s, count2); } /** Compare the string with another. @@ -2340,8 +2324,9 @@ public: size_type count1, const T& t) const { + string_view_type sv = t; return detail::lexicographical_compare( - subview(pos1, count1), string_view_type(t)); + data() + pos1, capped_length(pos1, count1), sv.data(), sv.size()); } /** Compare the string with another. @@ -2394,7 +2379,7 @@ public: size_type pos = 0, size_type count = npos) const { - return basic_static_string(&data()[pos], capped_length(pos, count)); + return basic_static_string(data() + pos, capped_length(pos, count)); } /** Return a view of a substring. @@ -2421,7 +2406,7 @@ public: size_type pos = 0, size_type count = npos) const { - return string_view_type(&data()[pos], capped_length(pos, count)); + return string_view_type(data() + pos, capped_length(pos, count)); } /** Copy a substring to another string. @@ -2459,7 +2444,10 @@ public: */ BOOST_STATIC_STRING_CPP14_CONSTEXPR void - resize(size_type n); + resize(size_type n) + { + resize(n, value_type()); + } /** Change the size of the string. @@ -4722,8 +4710,8 @@ struct hash< #ifndef BOOST_STATIC_STRING_STANDALONE return boost::hash_range(str.begin(), str.end()); #else - using view_type = typename boost::static_string:: - basic_static_string::string_view_type; + using view_type = typename + boost::static_string::basic_string_view; return std::hash()(view_type(str.data(), str.size())); #endif } @@ -4768,35 +4756,6 @@ assign( return term(); } -//template -//BOOST_STATIC_STRING_CPP14_CONSTEXPR -//auto -//basic_static_string:: -//assign(const basic_static_string& s) noexcept -> -// basic_static_string& -//{ -// if(this == &s) -// return *this; -// this->set_size(s.size()); -// traits_type::copy(data(), &s.data()[0], size() + 1); -// return *this; -//} - -template -template -BOOST_STATIC_STRING_CPP14_CONSTEXPR -auto -basic_static_string:: -assign( - const basic_static_string& s, - size_type pos, - size_type count) -> - basic_static_string& -{ - const auto ss = s.subview(pos, count); - return assign(ss.data(), ss.size()); -} - template BOOST_STATIC_STRING_CPP14_CONSTEXPR auto @@ -5023,21 +4982,6 @@ copy(pointer dest, size_type count, size_type pos) const -> return num_copied; } -template -BOOST_STATIC_STRING_CPP14_CONSTEXPR -void -basic_static_string:: -resize(size_type n) -{ - BOOST_STATIC_STRING_THROW_IF( - n > max_size(), std::length_error{"n > max_size()"}); - const auto curr_size = size(); - if(n > curr_size) - traits_type::assign(&data()[curr_size], n - curr_size, value_type()); - this->set_size(n); - term(); -} - template BOOST_STATIC_STRING_CPP14_CONSTEXPR void @@ -5048,7 +4992,7 @@ resize(size_type n, value_type c) n > max_size(), std::length_error{"n > max_size()"}); const auto curr_size = size(); if(n > curr_size) - traits_type::assign(&data()[curr_size], n - curr_size, c); + traits_type::assign(data() + curr_size, n - curr_size, c); this->set_size(n); term(); } @@ -5226,7 +5170,7 @@ find( return npos; if (!n) return pos; - const auto res = detail::search(&data()[pos], &data()[curr_size], s, &s[n], traits_type::eq); + const auto res = detail::search(data() + pos, data() + curr_size, s, s + n, traits_type::eq); return res == end() ? npos : detail::distance(data(), res); } @@ -5306,7 +5250,7 @@ find_first_not_of( return npos; if (!n) return pos; - const auto res = detail::find_not_of(&data()[pos], &data()[size()], s, n); + const auto res = detail::find_not_of(data() + pos, data() + size(), s, n); return res == end() ? npos : detail::distance(data(), res); }