diff --git a/include/boost/static_string/static_string.hpp b/include/boost/static_string/static_string.hpp index 26a9d75..e425500 100644 --- a/include/boost/static_string/static_string.hpp +++ b/include/boost/static_string/static_string.hpp @@ -2438,7 +2438,7 @@ public: BOOST_STATIC_STRING_CPP14_CONSTEXPR size_type copy( - CharT* dest, + pointer dest, size_type count, size_type pos = 0) const; @@ -4102,7 +4102,7 @@ private: } basic_static_string& - assign_char(value_type ch, std::false_type) + assign_char(value_type, std::false_type) { BOOST_STATIC_STRING_THROW( std::length_error{"max_size() == 0"}); @@ -4785,15 +4785,13 @@ template BOOST_STATIC_STRING_CPP14_CONSTEXPR auto basic_static_string:: -assign( - const basic_static_string& s) noexcept -> +assign(const basic_static_string& s) noexcept -> basic_static_string& { if(this == &s) return *this; this->set_size(s.size()); - const auto n = size() + 1; - traits_type::copy(data(), &s.data()[0], n); + traits_type::copy(data(), &s.data()[0], size() + 1); return *this; } @@ -5012,7 +5010,7 @@ template BOOST_STATIC_STRING_CPP14_CONSTEXPR auto basic_static_string:: -copy(CharT* dest, size_type count, size_type pos) const -> +copy(pointer dest, size_type count, size_type pos) const -> size_type { const auto s = subview(pos, count); diff --git a/test/static_string.cpp b/test/static_string.cpp index c01a183..b400cc9 100644 --- a/test/static_string.cpp +++ b/test/static_string.cpp @@ -3622,6 +3622,25 @@ testGeneral() s1.resize(2), std::length_error); } + // copy + { + { + static_string<20> str = "helloworld"; + char arr[20]{}; + BOOST_TEST(str.copy(arr, str.size()) == + str.size()); + BOOST_TEST(str == arr); + BOOST_TEST_THROWS( + str.copy(arr, str.size(), str.size() + 1), + std::out_of_range); + } + { + static_string<20> str = "helloworld"; + char arr[20]{}; + BOOST_TEST(str.copy(arr, 2, 2) == 2); + BOOST_TEST(arr[0] == 'l' && arr[1] == 'l'); + } + } } // done