Make StringView's copy constructor and assignment trivial. (#433)

This commit is contained in:
Branimir Karadžić
2026-09-27 22:12:50 -07:00
committed by GitHub
parent 58d36bd042
commit 279a4f84cd
3 changed files with 34 additions and 13 deletions

View File

@@ -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<bx::StringView>(), "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<Variant>(), "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") );
}