diff options
-rw-r--r-- | modules/codec/c++/data.hpp | 2 | ||||
-rw-r--r-- | modules/codec/tests/codec.cpp | 18 |
2 files changed, 19 insertions, 1 deletions
diff --git a/modules/codec/c++/data.hpp b/modules/codec/c++/data.hpp index 3fe7494..ca976d5 100644 --- a/modules/codec/c++/data.hpp +++ b/modules/codec/c++/data.hpp @@ -98,7 +98,7 @@ public: template<string_literal lit> data<typename parameter_pack_type<parameter_key_pack_index<lit, literals...>::value, T...>::type, encode::Native>& init(){ - value_ = data<typename parameter_pack_type<parameter_key_pack_index<lit, literals...>::value, T...>::type, encode::Native>{}; + value_.template emplace<parameter_key_pack_index<lit, literals...>::value>(); return get<lit>(); } diff --git a/modules/codec/tests/codec.cpp b/modules/codec/tests/codec.cpp index b9ac4ea..05899cc 100644 --- a/modules/codec/tests/codec.cpp +++ b/modules/codec/tests/codec.cpp @@ -24,6 +24,11 @@ using TestUnion = Union< Member<UInt64, "number"> >; +using TestSameTypeUnion = Union< + Member<UInt64, "one">, + Member<UInt64, "two"> +>; + using TestTuple = Tuple< TwoDimArray, UInt64 @@ -238,6 +243,19 @@ SAW_TEST("KelSimple Struct write and read back"){ SAW_EXPECT(native.template get<"number">().get() == 410, "Incorrect Decoding in number"); } +SAW_TEST("Native Union same type compilation"){ + using namespace saw; + + data<schema::TestSameTypeUnion, encode::Native> native; + + native.template init<"two">().set(50u); + + SAW_EXPECT(!native.template holds_alternative<"one">(), "Two should be initialized"); + SAW_EXPECT(native.template holds_alternative<"two">(), "Two should be initialized"); + + SAW_EXPECT(native.template get<"two">().get() == 50u, "Should be 50"); +} + SAW_TEST("KelSimple Union write and read back"){ using namespace saw; |