diff --git a/include/mp/type-map.h b/include/mp/type-map.h index ccfefb87..2a8c2068 100644 --- a/include/mp/type-map.h +++ b/include/mp/type-map.h @@ -12,8 +12,8 @@ #include namespace mp { -template -void CustomBuildField(TypeList>, +template +void CustomBuildField(TypeList>, Priority<1>, InvokeContext& invoke_context, Value&& value, @@ -51,8 +51,8 @@ auto EmplacePiecewiseSafe( } } -template -decltype(auto) CustomReadField(TypeList>, +template +decltype(auto) CustomReadField(TypeList>, Priority<1>, InvokeContext& invoke_context, Input&& input, diff --git a/include/mp/type-set.h b/include/mp/type-set.h index 902dd614..720ede7e 100644 --- a/include/mp/type-set.h +++ b/include/mp/type-set.h @@ -9,8 +9,8 @@ #include namespace mp { -template -void CustomBuildField(TypeList>, +template +void CustomBuildField(TypeList>, Priority<1>, InvokeContext& invoke_context, Value&& value, @@ -19,8 +19,8 @@ void CustomBuildField(TypeList>, BuildList(TypeList(), invoke_context, output, value); } -template -decltype(auto) CustomReadField(TypeList>, +template +decltype(auto) CustomReadField(TypeList>, Priority<1>, InvokeContext& invoke_context, Input&& input, diff --git a/include/mp/type-unordered-set.h b/include/mp/type-unordered-set.h index d1c714b2..12f07ef6 100644 --- a/include/mp/type-unordered-set.h +++ b/include/mp/type-unordered-set.h @@ -10,8 +10,8 @@ #include namespace mp { -template -void CustomBuildField(TypeList>, +template +void CustomBuildField(TypeList>, Priority<1>, InvokeContext& invoke_context, Value&& value, @@ -20,8 +20,8 @@ void CustomBuildField(TypeList>, BuildList(TypeList(), invoke_context, output, value); } -template -decltype(auto) CustomReadField(TypeList>, +template +decltype(auto) CustomReadField(TypeList>, Priority<1>, InvokeContext& invoke_context, Input&& input, diff --git a/include/mp/type-vector.h b/include/mp/type-vector.h index 7b5197ff..a7bb6a98 100644 --- a/include/mp/type-vector.h +++ b/include/mp/type-vector.h @@ -9,8 +9,8 @@ #include namespace mp { -template -void CustomBuildField(TypeList>, +template +void CustomBuildField(TypeList>, Priority<1>, InvokeContext& invoke_context, Value&& value, @@ -24,8 +24,8 @@ inline static bool BuildPrimitive(InvokeContext& invoke_context, std::vector -decltype(auto) CustomReadField(TypeList>, +template +decltype(auto) CustomReadField(TypeList>, Priority<1>, InvokeContext& invoke_context, Input&& input, diff --git a/test/mp/test/foo.capnp b/test/mp/test/foo.capnp index 392719ec..2480c8e2 100644 --- a/test/mp/test/foo.capnp +++ b/test/mp/test/foo.capnp @@ -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") { diff --git a/test/mp/test/foo.h b/test/mp/test/foo.h index e8782708..f6d4b7af 100644 --- a/test/mp/test/foo.h +++ b/test/mp/test/foo.h @@ -6,9 +6,11 @@ #define MP_TEST_FOO_H #include +#include #include #include #include +#include #include #include #include @@ -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; @@ -26,6 +34,11 @@ struct FooStruct std::optional optional_int; std::unordered_set unordered_set_int; std::map map_string_int; + // Containers with non-default comparator, allocator, and hash types. + std::set> set_int_desc; + std::pmr::vector pmr_vector_int; + std::unordered_set unordered_set_string_hash; + std::map> map_string_int_desc; }; enum class FooEnum : uint8_t { ONE = 1, TWO = 2, }; diff --git a/test/mp/test/test.cpp b/test/mp/test/test.cpp index 0492c9ee..7d35cf1e 100644 --- a/test/mp/test/test.cpp +++ b/test/mp/test/test.cpp @@ -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()); @@ -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);