diff --git a/include/bx/inline/string.inl b/include/bx/inline/string.inl index 82028ad..9aaa988 100644 --- a/include/bx/inline/string.inl +++ b/include/bx/inline/string.inl @@ -85,11 +85,6 @@ namespace bx { } - inline constexpr StringView::StringView(const StringView& _rhs) - { - set(_rhs); - } - inline constexpr StringView::StringView(const StringView& _rhs, int32_t _start, int32_t _len) { set(_rhs, _start, _len); @@ -101,12 +96,6 @@ namespace bx return *this; } - inline constexpr StringView& StringView::operator=(const StringView& _rhs) - { - set(_rhs); - return *this; - } - inline constexpr StringView::StringView(const char* _ptr) { set(_ptr, INT32_MAX); diff --git a/include/bx/string.h b/include/bx/string.h index e5efc22..409c08d 100644 --- a/include/bx/string.h +++ b/include/bx/string.h @@ -70,7 +70,7 @@ namespace bx constexpr StringView(const StringLiteral& _str); /// - constexpr StringView(const StringView& _rhs); + constexpr StringView(const StringView& _rhs) = default; /// constexpr StringView(const StringView& _rhs, int32_t _start, int32_t _len); @@ -79,7 +79,7 @@ namespace bx constexpr StringView& operator=(const char* _rhs); /// - constexpr StringView& operator=(const StringView& _rhs); + constexpr StringView& operator=(const StringView& _rhs) = default; /// constexpr StringView(const char* _ptr); diff --git a/tests/string_test.cpp b/tests/string_test.cpp index c5356a5..7fd4c8e 100644 --- a/tests/string_test.cpp +++ b/tests/string_test.cpp @@ -953,3 +953,35 @@ TEST_CASE("formatHumanNumber", "[string]") REQUIRE(testFormatHumanNumber("", 1389983113.891389, 2, 4) ); } + +TEST_CASE("StringView is trivially copyable", "[string]") +{ + static_assert(bx::isTriviallyCopyable(), "StringView must stay trivially copyable"); + + union Variant + { + struct { bx::StringView name; } named; + struct { int32_t value; } scalar; + }; + + struct Node + { + int32_t kind; + bx::StringView span; + Variant variant; + }; + + static_assert(bx::isTriviallyCopyable(), "a union holding a StringView must stay copyable"); + + const Node node = + { + .kind = 7, + .span = bx::StringView("span"), + .variant = { .named = { .name = bx::StringView("hello") } }, + }; + + const Node copy = node; + REQUIRE(7 == copy.kind); + REQUIRE(0 == bx::strCmp(copy.span, "span") ); + REQUIRE(0 == bx::strCmp(copy.variant.named.name, "hello") ); +}