diff --git a/include/flatmemory/details/types/bitset.hpp b/include/flatmemory/details/types/bitset.hpp index 9da8a27..b075ceb 100644 --- a/include/flatmemory/details/types/bitset.hpp +++ b/include/flatmemory/details/types/bitset.hpp @@ -852,8 +852,6 @@ void Builder>::resize_to_fit(const Other& other) { m_blocks.resize(other.get_blocks().size(), m_default_bit_value ? BitsetUtils::block_ones : BitsetUtils::block_zeroes); } - - assert(m_blocks.size() > 0); } template diff --git a/include/flatmemory/details/types/tuple.hpp b/include/flatmemory/details/types/tuple.hpp index 51af9ff..b2b56af 100644 --- a/include/flatmemory/details/types/tuple.hpp +++ b/include/flatmemory/details/types/tuple.hpp @@ -360,8 +360,7 @@ size_t Builder>::finish_iterative_impl(std::index_sequence, if constexpr (is_trivial) { /* Write the data inline. */ - auto& value = std::get(m_data); - out.write(pos + Layout>::data_positions[Is], value); + out.write(pos + Layout>::data_positions[Is], std::get(m_data)); } else { @@ -459,14 +458,6 @@ auto View>::get() } } -template -template -void View>::mutate(View>::element_type value) - requires(IsTriviallyCopyable>::element_type>) -{ - return write_value>::element_type>(m_buf + Layout>::data_positions[I], value); -} - template template auto View>::get() const @@ -485,6 +476,14 @@ auto View>::get() const } } +template +template +void View>::mutate(View>::element_type value) + requires(IsTriviallyCopyable>::element_type>) +{ + return write_value>::element_type>(m_buf + Layout>::data_positions[I], value); +} + template uint8_t* View>::buffer() { diff --git a/tests/unit/types/tuple.cpp b/tests/unit/types/tuple.cpp index d6a91b5..69b6a3a 100644 --- a/tests/unit/types/tuple.cpp +++ b/tests/unit/types/tuple.cpp @@ -290,19 +290,71 @@ struct StructTest uint64_t y; }; +static_assert(sizeof(StructTest) == 16); + TEST(FlatmemoryTests, TypesTupleStructTest) { - EXPECT_EQ((IsTriviallyCopyable>>), true); - EXPECT_EQ((IsTriviallyCopyable>), false); + EXPECT_EQ((IsTriviallyCopyable, StructTest>>>), true); + EXPECT_EQ((IsTriviallyCopyable, StructTest>>), false); - auto builder = Builder>(); - builder.get<0>().x = 5; - builder.get<0>().y = 10; + auto builder = Builder, StructTest>>(); + builder.get<0>().resize(1); + builder.get<1>().x = 5; + builder.get<1>().y = 10; builder.finish(); + EXPECT_EQ(builder.buffer().size(), 36); + + auto view = View, StructTest>>(builder.buffer().data()); + EXPECT_EQ(view.get<0>().size(), 1); + EXPECT_EQ(view.get<0>().at(0), 0); + EXPECT_EQ(view.get<1>().x, 5); + EXPECT_EQ(view.get<1>().y, 10); + EXPECT_EQ(view.buffer_size(), 36); +} + +/* +struct FlatSimpleEffect +{ + bool is_negated; + size_t atom_id; +}; // __attribute__((packed)); // Pack the struct to avoid padding + +static_assert(sizeof(FlatSimpleEffect) == 16); + +TEST(FlatmemoryTests, TypesTupleConditionalEffectTest) +{ + uint8_t buffer[16] = { 00, 00, 00, 00, 00, 00, 00, 00, 04, 00, 00, 00, 00, 00, 00, 00 }; + auto effect = read_value(buffer); + EXPECT_FALSE(effect.is_negated); + EXPECT_EQ(effect.atom_id, 4); + + using FlatIndexListLayout = flatmemory::Vector; + + using FlatConditionalEffectLayout = flatmemory::Tuple; // simple add or delete effect + + Layout().print(); + + auto builder = Builder(); + builder.get<0>().push_back(4); + builder.get<0>().push_back(10); + builder.get<3>().push_back(1); + builder.get<6>().is_negated = false; + builder.get<6>().atom_id = 4; + + builder.finish(); + + auto view = View(builder.buffer().data()); + print(builder.buffer().data(), builder.buffer().size()); - auto view = View>(builder.buffer().data()); - EXPECT_EQ(view.get<0>().x, 5); - EXPECT_EQ(view.get<0>().y, 10); + EXPECT_FALSE(view.get<6>().is_negated); + EXPECT_EQ(view.get<6>().atom_id, 4); } +*/ }