Skip to content

Commit

Permalink
Make static_string trivially copyable
Browse files Browse the repository at this point in the history
  • Loading branch information
Quuxplusone committed Mar 20, 2024
1 parent bff5cb6 commit 11781aa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
12 changes: 2 additions & 10 deletions include/boost/static_string/static_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1093,11 +1093,7 @@ class basic_static_string
Copy constructor.
*/
BOOST_STATIC_STRING_CPP14_CONSTEXPR
basic_static_string(const basic_static_string& other) noexcept
{
assign(other);
}
basic_static_string(const basic_static_string& other) = default;

/** Constructor.
Expand Down Expand Up @@ -1185,12 +1181,8 @@ class basic_static_string
@throw std::length_error `s.size() > max_size()`.
*/
BOOST_STATIC_STRING_CPP14_CONSTEXPR
basic_static_string&
operator=(const basic_static_string& s)
{
return assign(s);
}
operator=(const basic_static_string& s) = default;

/** Assign to the string.
Expand Down
39 changes: 39 additions & 0 deletions test/static_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,43 @@ testTWS(Arithmetic value, const wchar_t* wstr_expected = L"", bool test_expected
}
}

// done
static
void
testTypeTraits()
{
{
using S = static_string<1>;
static_assert(std::is_trivially_copyable<S>::value, "");
static_assert(!std::is_trivially_default_constructible<S>::value, "");
static_assert(std::is_trivially_copy_constructible<S>::value, "");
static_assert(std::is_trivially_move_constructible<S>::value, "");
static_assert(std::is_trivially_copy_assignable<S>::value, "");
static_assert(std::is_trivially_move_assignable<S>::value, "");
static_assert(std::is_trivially_destructible<S>::value, "");
}
{
using S = static_string<2>;
static_assert(std::is_trivially_copyable<S>::value, "");
static_assert(!std::is_trivially_default_constructible<S>::value, "");
static_assert(std::is_trivially_copy_constructible<S>::value, "");
static_assert(std::is_trivially_move_constructible<S>::value, "");
static_assert(std::is_trivially_copy_assignable<S>::value, "");
static_assert(std::is_trivially_move_assignable<S>::value, "");
static_assert(std::is_trivially_destructible<S>::value, "");
}
{
using S = static_string<3>;
static_assert(std::is_trivially_copyable<S>::value, "");
static_assert(!std::is_trivially_default_constructible<S>::value, "");
static_assert(std::is_trivially_copy_constructible<S>::value, "");
static_assert(std::is_trivially_move_constructible<S>::value, "");
static_assert(std::is_trivially_copy_assignable<S>::value, "");
static_assert(std::is_trivially_move_assignable<S>::value, "");
static_assert(std::is_trivially_destructible<S>::value, "");
}
}

// done
static
void
Expand Down Expand Up @@ -7461,6 +7498,8 @@ runTests()
constexpr auto cxper = testConstantEvaluation();
static_cast<void>(cxper);

testTypeTraits();

testConstruct();

testAssignment();
Expand Down

0 comments on commit 11781aa

Please sign in to comment.