Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions libraries/core/src/morpheus/core/conformance/flat_map.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#if __has_include(<flat_map>)
#include <flat_map>
#endif

// clang-format off
#if (__cpp_lib_flat_map>= 202207L)

namespace morpheus { namespace fm_ns = std; }

#else
#include <boost/container/flat_map.hpp>

namespace morpheus{ namespace fm_ns = boost; }

#endif
// clang-format on
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include "morpheus/core/serialisation/adapters/std/ranges.hpp"

#include <flat_map>

namespace morpheus::serialisation::detail
{

template <typename K, typename T, class C, class KC, class M>
inline constexpr bool isEnabledForRangeSerialisation<fm_ns::flat_map<K, T, C, KC, M>> = true;

} // namespace morpheus::serialisation::detail
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include "morpheus/core/serialisation/adapters/std/ranges.hpp"

#include <flat_map>

namespace morpheus::serialisation::detail
{

template <typename K, typename T, class C, class KC, class M>
inline constexpr bool isEnabledForRangeSerialisation<fm_ns::flat_multimap<K, T, C, KC, M>> = true;

} // namespace morpheus::serialisation::detail
23 changes: 23 additions & 0 deletions libraries/core/tests/conformance/flat_map.tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "morpheus/core/conformance/flat_map.hpp"

#include <catch2/catch_all.hpp>

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

24 changes: 24 additions & 0 deletions libraries/core/tests/serialisation/adapters/std/ranges.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, int>), (std::unordered_map<int, int>), (std::multimap<int, int>), (std::unordered_multimap<int, int>))
{
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<int>(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]")
{
Expand Down