From 11781aaf3a3f664d62bf7a3be066a7fe9a262dc4 Mon Sep 17 00:00:00 2001 From: Arthur O'Dwyer Date: Wed, 20 Mar 2024 16:42:01 -0400 Subject: [PATCH] Make static_string trivially copyable --- include/boost/static_string/static_string.hpp | 12 +----- test/static_string.cpp | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/include/boost/static_string/static_string.hpp b/include/boost/static_string/static_string.hpp index fce1ddb..71952e6 100644 --- a/include/boost/static_string/static_string.hpp +++ b/include/boost/static_string/static_string.hpp @@ -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. @@ -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. diff --git a/test/static_string.cpp b/test/static_string.cpp index db79c37..7c25f97 100644 --- a/test/static_string.cpp +++ b/test/static_string.cpp @@ -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::value, ""); + static_assert(!std::is_trivially_default_constructible::value, ""); + static_assert(std::is_trivially_copy_constructible::value, ""); + static_assert(std::is_trivially_move_constructible::value, ""); + static_assert(std::is_trivially_copy_assignable::value, ""); + static_assert(std::is_trivially_move_assignable::value, ""); + static_assert(std::is_trivially_destructible::value, ""); + } + { + using S = static_string<2>; + static_assert(std::is_trivially_copyable::value, ""); + static_assert(!std::is_trivially_default_constructible::value, ""); + static_assert(std::is_trivially_copy_constructible::value, ""); + static_assert(std::is_trivially_move_constructible::value, ""); + static_assert(std::is_trivially_copy_assignable::value, ""); + static_assert(std::is_trivially_move_assignable::value, ""); + static_assert(std::is_trivially_destructible::value, ""); + } + { + using S = static_string<3>; + static_assert(std::is_trivially_copyable::value, ""); + static_assert(!std::is_trivially_default_constructible::value, ""); + static_assert(std::is_trivially_copy_constructible::value, ""); + static_assert(std::is_trivially_move_constructible::value, ""); + static_assert(std::is_trivially_copy_assignable::value, ""); + static_assert(std::is_trivially_move_assignable::value, ""); + static_assert(std::is_trivially_destructible::value, ""); + } +} + // done static void @@ -7461,6 +7498,8 @@ runTests() constexpr auto cxper = testConstantEvaluation(); static_cast(cxper); + testTypeTraits(); + testConstruct(); testAssignment();