Skip to content
Open
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
8 changes: 4 additions & 4 deletions include/mp/type-map.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <map>

namespace mp {
template <typename KeyLocalType, typename ValueLocalType, typename Value, typename Output>
void CustomBuildField(TypeList<std::map<KeyLocalType, ValueLocalType>>,
template <typename KeyLocalType, typename ValueLocalType, typename Compare, typename Allocator, typename Value, typename Output>
void CustomBuildField(TypeList<std::map<KeyLocalType, ValueLocalType, Compare, Allocator>>,
Priority<1>,
InvokeContext& invoke_context,
Value&& value,
Expand Down Expand Up @@ -51,8 +51,8 @@ auto EmplacePiecewiseSafe(
}
}

template <typename KeyLocalType, typename ValueLocalType, typename Input, typename ReadDest>
decltype(auto) CustomReadField(TypeList<std::map<KeyLocalType, ValueLocalType>>,
template <typename KeyLocalType, typename ValueLocalType, typename Compare, typename Allocator, typename Input, typename ReadDest>
decltype(auto) CustomReadField(TypeList<std::map<KeyLocalType, ValueLocalType, Compare, Allocator>>,
Priority<1>,
InvokeContext& invoke_context,
Input&& input,
Expand Down
8 changes: 4 additions & 4 deletions include/mp/type-set.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include <mp/util.h>

namespace mp {
template <typename LocalType, typename Value, typename Output>
void CustomBuildField(TypeList<std::set<LocalType>>,
template <typename LocalType, typename Compare, typename Allocator, typename Value, typename Output>
void CustomBuildField(TypeList<std::set<LocalType, Compare, Allocator>>,
Priority<1>,
InvokeContext& invoke_context,
Value&& value,
Expand All @@ -19,8 +19,8 @@ void CustomBuildField(TypeList<std::set<LocalType>>,
BuildList(TypeList<LocalType>(), invoke_context, output, value);
}

template <typename LocalType, typename Input, typename ReadDest>
decltype(auto) CustomReadField(TypeList<std::set<LocalType>>,
template <typename LocalType, typename Compare, typename Allocator, typename Input, typename ReadDest>
decltype(auto) CustomReadField(TypeList<std::set<LocalType, Compare, Allocator>>,
Priority<1>,
InvokeContext& invoke_context,
Input&& input,
Expand Down
8 changes: 4 additions & 4 deletions include/mp/type-unordered-set.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <unordered_set>

namespace mp {
template <typename LocalType, typename Value, typename Output>
void CustomBuildField(TypeList<std::unordered_set<LocalType>>,
template <typename LocalType, typename Hash, typename KeyEqual, typename Allocator, typename Value, typename Output>
void CustomBuildField(TypeList<std::unordered_set<LocalType, Hash, KeyEqual, Allocator>>,
Priority<1>,
InvokeContext& invoke_context,
Value&& value,
Expand All @@ -20,8 +20,8 @@ void CustomBuildField(TypeList<std::unordered_set<LocalType>>,
BuildList(TypeList<LocalType>(), invoke_context, output, value);
}

template <typename LocalType, typename Input, typename ReadDest>
decltype(auto) CustomReadField(TypeList<std::unordered_set<LocalType>>,
template <typename LocalType, typename Hash, typename KeyEqual, typename Allocator, typename Input, typename ReadDest>
decltype(auto) CustomReadField(TypeList<std::unordered_set<LocalType, Hash, KeyEqual, Allocator>>,
Priority<1>,
InvokeContext& invoke_context,
Input&& input,
Expand Down
8 changes: 4 additions & 4 deletions include/mp/type-vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include <mp/util.h>

namespace mp {
template <typename LocalType, typename Value, typename Output>
void CustomBuildField(TypeList<std::vector<LocalType>>,
template <typename LocalType, typename Allocator, typename Value, typename Output>
void CustomBuildField(TypeList<std::vector<LocalType, Allocator>>,
Priority<1>,
InvokeContext& invoke_context,
Value&& value,
Expand All @@ -24,8 +24,8 @@ inline static bool BuildPrimitive(InvokeContext& invoke_context, std::vector<boo
return value;
}

template <typename LocalType, typename Input, typename ReadDest>
decltype(auto) CustomReadField(TypeList<std::vector<LocalType>>,
template <typename LocalType, typename Allocator, typename Input, typename ReadDest>
decltype(auto) CustomReadField(TypeList<std::vector<LocalType, Allocator>>,
Priority<1>,
InvokeContext& invoke_context,
Input&& input,
Expand Down
4 changes: 4 additions & 0 deletions test/mp/test/foo.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ struct FooStruct $Proxy.wrap("mp::test::FooStruct") {
hasOptionalInt @4 :Bool;
unorderedSetInt @5 :List(Int32) $Proxy.name("unordered_set_int");
mapStringInt @6 :List(StringIntPair) $Proxy.name("map_string_int");
setIntDesc @7 :List(Int32) $Proxy.name("set_int_desc");
pmrVectorInt @8 :List(Int32) $Proxy.name("pmr_vector_int");
unorderedSetStringHash @9 :List(Text) $Proxy.name("unordered_set_string_hash");
mapStringIntDesc @10 :List(StringIntPair) $Proxy.name("map_string_int_desc");
}

struct FooCustom $Proxy.wrap("mp::test::FooCustom") {
Expand Down
13 changes: 13 additions & 0 deletions test/mp/test/foo.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
#define MP_TEST_FOO_H

#include <cassert>
#include <cstddef>
#include <functional>
#include <map>
#include <memory>
#include <memory_resource>
#include <optional>
#include <string>
#include <set>
Expand All @@ -18,6 +20,12 @@
namespace mp {
namespace test {

//! Hash function used to test std::unordered_set with a custom hash.
struct FooHash
{
size_t operator()(const std::string& str) const { return str.size(); }
};

struct FooStruct
{
std::string name;
Expand All @@ -26,6 +34,11 @@ struct FooStruct
std::optional<int> optional_int;
std::unordered_set<int> unordered_set_int;
std::map<std::string, int> map_string_int;
// Containers with non-default comparator, allocator, and hash types.
std::set<int, std::greater<>> set_int_desc;
std::pmr::vector<int> pmr_vector_int;
std::unordered_set<std::string, FooHash> unordered_set_string_hash;
std::map<std::string, int, std::greater<>> map_string_int_desc;
};

enum class FooEnum : uint8_t { ONE = 1, TWO = 2, };
Expand Down
8 changes: 8 additions & 0 deletions test/mp/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ KJ_TEST("Call FooInterface methods")
in.optional_int = 3;
in.map_string_int.emplace("a", 1);
in.map_string_int.emplace("b", 2);
in.set_int_desc = {1, 2, 3};
in.pmr_vector_int = {3, 1, 2};
in.unordered_set_string_hash = {"a", "bb"};
in.map_string_int_desc = {{"a", 1}, {"b", 2}};
FooStruct out = foo->pass(in);
KJ_EXPECT(in.name == out.name);
KJ_EXPECT(in.set_int.size() == out.set_int.size());
Expand All @@ -194,6 +198,10 @@ KJ_TEST("Call FooInterface methods")
KJ_EXPECT(init->first == outit->first);
KJ_EXPECT(init->second == outit->second);
}
KJ_EXPECT(in.set_int_desc == out.set_int_desc);
KJ_EXPECT(in.pmr_vector_int == out.pmr_vector_int);
KJ_EXPECT(in.unordered_set_string_hash == out.unordered_set_string_hash);
KJ_EXPECT(in.map_string_int_desc == out.map_string_int_desc);

// Additional checks for std::optional member
KJ_EXPECT(foo->pass(in).optional_int == 3);
Expand Down
Loading