forked from boostorg/static_string
Add copy tests
This commit is contained in:
@ -2438,7 +2438,7 @@ public:
|
|||||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||||
size_type
|
size_type
|
||||||
copy(
|
copy(
|
||||||
CharT* dest,
|
pointer dest,
|
||||||
size_type count,
|
size_type count,
|
||||||
size_type pos = 0) const;
|
size_type pos = 0) const;
|
||||||
|
|
||||||
@ -4102,7 +4102,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
basic_static_string&
|
basic_static_string&
|
||||||
assign_char(value_type ch, std::false_type)
|
assign_char(value_type, std::false_type)
|
||||||
{
|
{
|
||||||
BOOST_STATIC_STRING_THROW(
|
BOOST_STATIC_STRING_THROW(
|
||||||
std::length_error{"max_size() == 0"});
|
std::length_error{"max_size() == 0"});
|
||||||
@ -4785,15 +4785,13 @@ template<std::size_t N, typename CharT, typename Traits>
|
|||||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||||
auto
|
auto
|
||||||
basic_static_string<N, CharT, Traits>::
|
basic_static_string<N, CharT, Traits>::
|
||||||
assign(
|
assign(const basic_static_string& s) noexcept ->
|
||||||
const basic_static_string& s) noexcept ->
|
|
||||||
basic_static_string&
|
basic_static_string&
|
||||||
{
|
{
|
||||||
if(this == &s)
|
if(this == &s)
|
||||||
return *this;
|
return *this;
|
||||||
this->set_size(s.size());
|
this->set_size(s.size());
|
||||||
const auto n = size() + 1;
|
traits_type::copy(data(), &s.data()[0], size() + 1);
|
||||||
traits_type::copy(data(), &s.data()[0], n);
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5012,7 +5010,7 @@ template<std::size_t N, typename CharT, typename Traits>
|
|||||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||||
auto
|
auto
|
||||||
basic_static_string<N, CharT, Traits>::
|
basic_static_string<N, CharT, Traits>::
|
||||||
copy(CharT* dest, size_type count, size_type pos) const ->
|
copy(pointer dest, size_type count, size_type pos) const ->
|
||||||
size_type
|
size_type
|
||||||
{
|
{
|
||||||
const auto s = subview(pos, count);
|
const auto s = subview(pos, count);
|
||||||
|
@ -3622,6 +3622,25 @@ testGeneral()
|
|||||||
s1.resize(2),
|
s1.resize(2),
|
||||||
std::length_error);
|
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
|
// done
|
||||||
|
Reference in New Issue
Block a user