diff --git a/libraries/core/src/morpheus/core/conformance/flat_map.hpp b/libraries/core/src/morpheus/core/conformance/flat_map.hpp new file mode 100644 index 000000000..befd2c1b9 --- /dev/null +++ b/libraries/core/src/morpheus/core/conformance/flat_map.hpp @@ -0,0 +1,18 @@ +#pragma once + +#if __has_include() + #include +#endif + +// clang-format off +#if (__cpp_lib_flat_map>= 202207L) + + namespace morpheus { namespace fm_ns = std; } + +#else + #include + + namespace morpheus{ namespace fm_ns = boost; } + +#endif +// clang-format on diff --git a/libraries/core/src/morpheus/core/serialisation/adapters/std/flat_map.hpp b/libraries/core/src/morpheus/core/serialisation/adapters/std/flat_map.hpp new file mode 100644 index 000000000..74994af46 --- /dev/null +++ b/libraries/core/src/morpheus/core/serialisation/adapters/std/flat_map.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "morpheus/core/serialisation/adapters/std/ranges.hpp" + +#include + +namespace morpheus::serialisation::detail +{ + +template +inline constexpr bool isEnabledForRangeSerialisation> = true; + +} // namespace morpheus::serialisation::detail diff --git a/libraries/core/src/morpheus/core/serialisation/adapters/std/flat_multimap.hpp b/libraries/core/src/morpheus/core/serialisation/adapters/std/flat_multimap.hpp new file mode 100644 index 000000000..7da0f1d9e --- /dev/null +++ b/libraries/core/src/morpheus/core/serialisation/adapters/std/flat_multimap.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "morpheus/core/serialisation/adapters/std/ranges.hpp" + +#include + +namespace morpheus::serialisation::detail +{ + +template +inline constexpr bool isEnabledForRangeSerialisation> = true; + +} // namespace morpheus::serialisation::detail diff --git a/libraries/core/tests/conformance/flat_map.tests.cpp b/libraries/core/tests/conformance/flat_map.tests.cpp new file mode 100644 index 000000000..ad109ab11 --- /dev/null +++ b/libraries/core/tests/conformance/flat_map.tests.cpp @@ -0,0 +1,23 @@ +#include "morpheus/core/conformance/flat_map.hpp" + +#include + +namespace morpheus +{ + +TEST_CASE("Ensure flat_map library is supported and working", "[morpheus.conformance.flat_map]") +{ +// using namespace std::chrono_literals; + using namespace fm_ns; + + /* // Ensure time zones work + REQUIRE(date_ns::locate_zone("Europe/London")); + + STATIC_REQUIRE((year{ 2022 } / month{ 11 } / day{ 8 }) == year_month_day(year{ 2022 }, month{ 11 }, day{ 8 })); + STATIC_REQUIRE(weeks{ 1 } == days{ 7 }); + STATIC_REQUIRE(years{ 1 } == months{ 12 }); +*/ +} + +} // morpheus + diff --git a/libraries/core/tests/serialisation/adapters/std/ranges.tests.cpp b/libraries/core/tests/serialisation/adapters/std/ranges.tests.cpp index ad8e224b5..27b9b07eb 100644 --- a/libraries/core/tests/serialisation/adapters/std/ranges.tests.cpp +++ b/libraries/core/tests/serialisation/adapters/std/ranges.tests.cpp @@ -44,6 +44,30 @@ TEMPLATE_TEST_CASE("Verify serialisation of sequence containers std::ranges", "[ } } +TEMPLATE_TEST_CASE("Verify serialisation of associative containers std::ranges", "[morpheus.serialisation.ranges.serialise.associative_containers]", + (std::map), (std::unordered_map), (std::multimap), (std::unordered_multimap)) +{ + GIVEN("A range of values") + { + MapType container; + + auto key = GENERATE(take(10, random(-100, 100))); + auto value = GENERATE(take(10, random(-100, 100))); + + THEN("Expect the following sequence of operations on the underlying writer") + { + + InSequence seq; + MockedWriteSerialiser serialiser; + EXPECT_CALL(serialiser.writer(), beginSequence(std::optional(ranges::size(container)))).Times(1); + ranges::for_each(container, [&serialiser](auto const& element) { EXPECT_CALL(serialiser.writer(), write(Matcher(Eq(element)))).Times(1); }); + EXPECT_CALL(serialiser.writer(), endSequence()).Times(1); + + WHEN("Serialising the std::expected") { serialiser.serialise(container); } + } + } +} + /* TEST_CASE("Verify deserialisation of std::ranges", "[morpheus.serialisation.ranges.deserialise]") {