diff --git a/include/boost/static_string/static_string.hpp b/include/boost/static_string/static_string.hpp index 1d0da6c..e857345 100644 --- a/include/boost/static_string/static_string.hpp +++ b/include/boost/static_string/static_string.hpp @@ -1197,7 +1197,7 @@ public: basic_static_string& assign(const T& t) { - string_view_type sv = t; + const string_view_type sv = t; return assign(sv.data(), sv.size()); } @@ -1958,7 +1958,8 @@ public: size_type index, const T& t) { - return insert(index, t, 0, npos); + const string_view_type sv = t; + return insert(index, sv.data(), sv.size()); } /** Insert characters from an object convertible to `string_view_type`. @@ -2447,7 +2448,7 @@ public: int compare(const T& t) const noexcept { - string_view_type sv = t; + const string_view_type sv = t; return detail::lexicographical_compare( data(), size(), sv.data(), sv.size()); } @@ -2474,7 +2475,7 @@ public: size_type count1, const T& t) const { - string_view_type sv = t; + const string_view_type sv = t; return detail::lexicographical_compare( data() + pos1, capped_length(pos1, count1), sv.data(), sv.size()); } @@ -2785,7 +2786,7 @@ public: size_type n1, const T& t) { - string_view_type sv = t; + const string_view_type sv = t; return replace(pos1, n1, sv.data(), sv.size()); } @@ -2837,7 +2838,7 @@ public: size_type pos2, size_type n2 = npos) { - string_view_type sv = t; + const string_view_type sv = t; return replace(pos1, n1, sv.substr(pos2, n2)); } @@ -3043,7 +3044,7 @@ public: const_iterator i2, const T& t) { - string_view_type sv = t; + const string_view_type sv = t; return replace(i1, i2, sv.begin(), sv.end()); } @@ -3306,7 +3307,7 @@ public: size_type pos = 0) const noexcept(detail::is_nothrow_convertible::value) { - string_view_type sv = t; + const string_view_type sv = t; return find(sv.data(), pos, sv.size()); } @@ -3459,7 +3460,7 @@ public: size_type pos = npos) const noexcept(detail::is_nothrow_convertible::value) { - string_view_type sv = t; + const string_view_type sv = t; return rfind(sv.data(), pos, sv.size()); } @@ -3607,7 +3608,7 @@ public: size_type pos = 0) const noexcept(detail::is_nothrow_convertible::value) { - string_view_type sv = t; + const string_view_type sv = t; return find_first_of(sv.data(), pos, sv.size()); } @@ -3750,7 +3751,7 @@ public: size_type pos = npos) const noexcept(detail::is_nothrow_convertible::value) { - string_view_type sv = t; + const string_view_type sv = t; return find_last_of(sv.data(), pos, sv.size()); } @@ -3892,7 +3893,7 @@ public: size_type pos = 0) const noexcept(detail::is_nothrow_convertible::value) { - string_view_type sv = t; + const string_view_type sv = t; return find_first_not_of(sv.data(), pos, sv.size()); } @@ -4033,7 +4034,7 @@ public: size_type pos = npos) const noexcept(detail::is_nothrow_convertible::value) { - string_view_type sv = t; + const string_view_type sv = t; return find_last_not_of(sv.data(), pos, sv.size()); } diff --git a/test/static_string.cpp b/test/static_string.cpp index f29ea8d..14a0ea7 100644 --- a/test/static_string.cpp +++ b/test/static_string.cpp @@ -71,7 +71,6 @@ bool testI(S s, typename S::size_type pos, const typename S::value_type* str, typename S::size_type n, S expected) { const typename S::size_type old_size = s.size(); - S s0 = s; if (pos <= old_size) { s.insert(pos, str, n); @@ -89,7 +88,6 @@ bool testE(S s, typename S::size_type pos, typename S::size_type n, S expected) { const typename S::size_type old_size = s.size(); - S s0 = s; if (pos <= old_size) { s.erase(pos, n); @@ -189,7 +187,6 @@ bool testR(S s, typename S::size_type pos, typename S::size_type n1, typename S::size_type n2, typename S::value_type c, S expected) { const typename S::size_type old_size = s.size(); - S s0 = s; if (pos <= old_size) { s.replace(pos, n1, n2, c); @@ -2109,7 +2106,6 @@ testAppend() S("1234567890123456789012345678901234567890"))); S s_short = "123/"; - S s_long = "Lorem ipsum dolor sit amet, consectetur/"; s_short.append(s_short.data(), s_short.size()); BOOST_TEST(s_short == "123/123/"); @@ -3764,11 +3760,11 @@ testFind() BOOST_TEST(fs1.find(cs2, 0, 2) == 1); - BOOST_TEST(fs1.find(cs1, 4) == -1); - BOOST_TEST(fs1.find(cs2, 4) == -1); + BOOST_TEST(fs1.find(cs1, 4) == S::npos); + BOOST_TEST(fs1.find(cs2, 4) == S::npos); BOOST_TEST(fs1.find('1') == 0); - BOOST_TEST(fs1.find('1', 4) == -1); + BOOST_TEST(fs1.find('1', 4) == S::npos); BOOST_TEST(testF(S(""), "", 0, 0, 0)); BOOST_TEST(testF(S(""), "abcde", 0, 0, 0)); @@ -4071,22 +4067,6 @@ testFind() BOOST_TEST(testF(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 10, S::npos)); BOOST_TEST(testF(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 0, 20)); - - - - - - - - - - - - - - - - // rfind BOOST_TEST(fs1.rfind(v1) == 0); @@ -4099,9 +4079,9 @@ testFind() BOOST_TEST(fs1.rfind(cs2) == 1); BOOST_TEST(fs1.rfind(cs1, 0) == 0); - BOOST_TEST(fs1.rfind(cs2, 0) == -1); + BOOST_TEST(fs1.rfind(cs2, 0) == S::npos); - BOOST_TEST(fs1.rfind(cs2, 0, 2) == -1); + BOOST_TEST(fs1.rfind(cs2, 0, 2) == S::npos); BOOST_TEST(fs1.rfind(cs1, 4) == 0); BOOST_TEST(fs1.rfind('1') == 0); @@ -4409,15 +4389,6 @@ testFind() BOOST_TEST(testRF(S("abcdeabcdeabcdeabcde"), "abcdeabcde", 20, 10, 10)); BOOST_TEST(testRF(S("abcdeabcdeabcdeabcde"), "abcdeabcdeabcdeabcde", 20, 0, 20)); - - - - - - - - - // find_first_of BOOST_TEST(fs1.find_first_of(v1) == 0); @@ -4437,7 +4408,7 @@ testFind() BOOST_TEST(fs1.find_first_of(cs2, 4) == 4); BOOST_TEST(fs1.find_first_of('1') == 0); - BOOST_TEST(fs1.find_first_of('1', 4) == -1); + BOOST_TEST(fs1.find_first_of('1', 4) == S::npos); BOOST_TEST(testFF(S(""), "", 0, 0, S::npos)); BOOST_TEST(testFF(S(""), "irkhs", 0, 0, S::npos)); @@ -4740,13 +4711,6 @@ testFind() BOOST_TEST(testFF(S("fbkeiopclstmdqranjhg"), "trqncbkgmh", 20, 10, S::npos)); BOOST_TEST(testFF(S("lifhpdgmbconstjeqark"), "tomglrkencbsfjqpihda", 20, 0, S::npos)); - - - - - - - // find_last_of BOOST_TEST(fs1.find_last_of(v1) == 4); @@ -4758,15 +4722,15 @@ testFind() BOOST_TEST(fs1.find_last_of(cs2) == 4); BOOST_TEST(fs1.find_last_of(cs1, 0) == 0); - BOOST_TEST(fs1.find_last_of(cs2, 0) == -1); + BOOST_TEST(fs1.find_last_of(cs2, 0) == S::npos); - BOOST_TEST(fs1.find_last_of(cs2, 0, 2) == -1); + BOOST_TEST(fs1.find_last_of(cs2, 0, 2) == S::npos); BOOST_TEST(fs1.find_last_of(cs1, 4) == 4); BOOST_TEST(fs1.find_last_of(cs2, 4) == 4); BOOST_TEST(fs1.find_last_of('1') == 0); - BOOST_TEST(fs1.find_last_of('5', 3) == -1); + BOOST_TEST(fs1.find_last_of('5', 3) == S::npos); BOOST_TEST(testFL(S(""), "", 0, 0, S::npos)); BOOST_TEST(testFL(S(""), "irkhs", 0, 0, S::npos)); @@ -5117,8 +5081,8 @@ testFind() BOOST_TEST(fs1.find_first_not_of(cs4, 0, 2) == 0); - BOOST_TEST(fs1.find_first_not_of(cs3, 4) == -1); - BOOST_TEST(fs1.find_first_not_of(cs4, 4) == -1); + BOOST_TEST(fs1.find_first_not_of(cs3, 4) == S::npos); + BOOST_TEST(fs1.find_first_not_of(cs4, 4) == S::npos); BOOST_TEST(fs1.find_first_not_of('1') == 1); BOOST_TEST(fs1.find_first_not_of('1', 3) == 3); @@ -5458,7 +5422,7 @@ testFind() BOOST_TEST(fs1.find_last_not_of(cs3) == 2); BOOST_TEST(fs1.find_last_not_of(cs4) == 3); - BOOST_TEST(fs1.find_last_not_of(cs3, 0) == -1); + BOOST_TEST(fs1.find_last_not_of(cs3, 0) == S::npos); BOOST_TEST(fs1.find_last_not_of(cs4, 0) == 0); BOOST_TEST(fs1.find_last_not_of(cs4, 0, 2) == 0); @@ -7149,6 +7113,7 @@ int runTests() { constexpr auto cxper = testConstantEvaluation(); + static_cast(cxper); testConstruct();