Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make static_string trivially copyable #57

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
49 changes: 49 additions & 0 deletions test/static_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,53 @@ testTWS(Arithmetic value, const wchar_t* wstr_expected = L"", bool test_expected
}
}

// done
static
void
testTypeTraits()
{
{
using S = static_string<0>;
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<1>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is

using S = static_string<0>;

a thing we need to test?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure; updated.

Re "That sounds great" — unclear whether you mean "great" in re "open a new PR for trivially relocatable" (which makes sense only if you don't want to take this one — trivially copyable types are trivially relocatable by definition) or just generally expressing contentment with this PR. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just generally expressing contentment with this PR. :)

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<20>;
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<400>;
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 +7508,8 @@ runTests()
constexpr auto cxper = testConstantEvaluation();
static_cast<void>(cxper);

testTypeTraits();

testConstruct();

testAssignment();
Expand Down
Loading