mirror of
https://github.com/boostorg/static_string.git
synced 2025-07-29 20:17:35 +02:00
Add unchecked assignment
This commit is contained in:
@ -940,36 +940,40 @@ public:
|
|||||||
|
|
||||||
Replace the contents with a copy of another `basic_static_string`
|
Replace the contents with a copy of another `basic_static_string`
|
||||||
|
|
||||||
|
@throw std::length_error if `s.size() > max_size()`
|
||||||
@return `*this`
|
@return `*this`
|
||||||
*/
|
*/
|
||||||
|
template<std::size_t M
|
||||||
|
#ifndef GENERATING_DOCUMENTATION
|
||||||
|
, typename std::enable_if<(M < N)>::type* = nullptr
|
||||||
|
#endif
|
||||||
|
>
|
||||||
|
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||||
|
basic_static_string&
|
||||||
|
assign(const basic_static_string<M, CharT, Traits>& s)
|
||||||
|
{
|
||||||
|
return assign_unchecked(s.data(), s.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef GENERATING_DOCUMENTATION
|
||||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||||
basic_static_string&
|
basic_static_string&
|
||||||
assign(const basic_static_string& s) noexcept
|
assign(const basic_static_string& s) noexcept
|
||||||
{
|
{
|
||||||
if (this == &s)
|
if (this == &s)
|
||||||
return *this;
|
return *this;
|
||||||
this->set_size(s.size());
|
return assign_unchecked(s.data(), s.size());
|
||||||
traits_type::copy(data(), &s.data()[0], size() + 1);
|
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Replace the contents.
|
template<std::size_t M,
|
||||||
|
typename std::enable_if<(M > N)>::type* = nullptr>
|
||||||
Replace the contents with a copy of another `basic_static_string`
|
|
||||||
|
|
||||||
@throw std::length_error if `s.size() > max_size()`
|
|
||||||
@return `*this`
|
|
||||||
*/
|
|
||||||
template<std::size_t M>
|
|
||||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||||
basic_static_string&
|
basic_static_string&
|
||||||
assign(const basic_static_string<M, CharT, Traits>& s)
|
assign(const basic_static_string<M, CharT, Traits>& s)
|
||||||
{
|
{
|
||||||
// VFALCO this could come in two flavors,
|
|
||||||
// N > M and N < M, and skip the exception
|
|
||||||
// check when N > M
|
|
||||||
return assign(s.data(), s.size());
|
return assign(s.data(), s.size());
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/** Replace the contents.
|
/** Replace the contents.
|
||||||
|
|
||||||
@ -4103,6 +4107,12 @@ private:
|
|||||||
const_pointer s,
|
const_pointer s,
|
||||||
size_type count);
|
size_type count);
|
||||||
|
|
||||||
|
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||||
|
basic_static_string&
|
||||||
|
assign_unchecked(
|
||||||
|
const_pointer s,
|
||||||
|
size_type count) noexcept;
|
||||||
|
|
||||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||||
size_type
|
size_type
|
||||||
capped_length(
|
capped_length(
|
||||||
@ -4987,9 +4997,9 @@ basic_static_string<N, CharT, Traits>::
|
|||||||
copy(pointer 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 num_copied = capped_length(pos, count);
|
||||||
traits_type::copy(dest, s.data(), s.size());
|
traits_type::copy(dest, data() + pos, num_copied);
|
||||||
return s.size();
|
return num_copied;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t N, typename CharT, typename Traits>
|
template<std::size_t N, typename CharT, typename Traits>
|
||||||
@ -5372,6 +5382,21 @@ insert_unchecked(
|
|||||||
this->set_size(curr_size + count);
|
this->set_size(curr_size + count);
|
||||||
return curr_data + index;
|
return curr_data + index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<std::size_t N, typename CharT, typename Traits>
|
||||||
|
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||||
|
auto
|
||||||
|
basic_static_string<N, CharT, Traits>::
|
||||||
|
assign_unchecked(
|
||||||
|
const_pointer s,
|
||||||
|
size_type count) noexcept ->
|
||||||
|
basic_static_string&
|
||||||
|
{
|
||||||
|
this->set_size(count);
|
||||||
|
traits_type::copy(data(), s, size() + 1);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
} // static_string
|
} // static_string
|
||||||
} // boost
|
} // boost
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user