Skip to content

Commit 079277f

Browse files
committed
moveonly: add mp/type-map.h
1 parent 6a68472 commit 079277f

File tree

4 files changed

+53
-39
lines changed

4 files changed

+53
-39
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ set(MP_PUBLIC_HEADERS
4646
include/mp/proxy-types.h
4747
include/mp/proxy.h
4848
include/mp/type-context.h
49+
include/mp/type-map.h
4950
include/mp/type-optional.h
5051
include/mp/type-pointer.h
5152
include/mp/type-set.h

include/mp/proxy-types.h

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -143,29 +143,6 @@ struct ReadDestUpdate
143143

144144

145145

146-
147-
148-
template <typename KeyLocalType, typename ValueLocalType, typename Input, typename ReadDest>
149-
decltype(auto) CustomReadField(TypeList<std::map<KeyLocalType, ValueLocalType>>,
150-
Priority<1>,
151-
InvokeContext& invoke_context,
152-
Input&& input,
153-
ReadDest&& read_dest)
154-
{
155-
return read_dest.update([&](auto& value) {
156-
auto data = input.get();
157-
value.clear();
158-
for (auto item : data) {
159-
ReadField(TypeList<std::pair<const KeyLocalType, ValueLocalType>>(), invoke_context,
160-
Make<ValueField>(item),
161-
ReadDestEmplace(
162-
TypeList<std::pair<const KeyLocalType, ValueLocalType>>(), [&](auto&&... args) -> auto& {
163-
return *value.emplace(std::forward<decltype(args)>(args)...).first;
164-
}));
165-
}
166-
});
167-
}
168-
169146
template <typename KeyLocalType, typename ValueLocalType, typename Input, typename ReadDest>
170147
decltype(auto) CustomReadField(TypeList<std::pair<KeyLocalType, ValueLocalType>>,
171148
Priority<1>,
@@ -579,22 +556,6 @@ struct ListOutput<::capnp::List<T, kind>>
579556
// clang-format on
580557
};
581558

582-
template <typename KeyLocalType, typename ValueLocalType, typename Value, typename Output>
583-
void CustomBuildField(TypeList<std::map<KeyLocalType, ValueLocalType>>,
584-
Priority<1>,
585-
InvokeContext& invoke_context,
586-
Value&& value,
587-
Output&& output)
588-
{
589-
// FIXME dededup with vector handler above
590-
auto list = output.init(value.size());
591-
size_t i = 0;
592-
for (const auto& elem : value) {
593-
BuildField(TypeList<std::pair<KeyLocalType, ValueLocalType>>(), invoke_context,
594-
ListOutput<typename decltype(list)::Builds>(list, i), elem);
595-
++i;
596-
}
597-
}
598559
template <typename Value>
599560
::capnp::Void BuildPrimitive(InvokeContext& invoke_context, Value&&, TypeList<::capnp::Void>)
600561
{

include/mp/type-map.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) 2025 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef MP_PROXY_TYPE_MAP_H
6+
#define MP_PROXY_TYPE_MAP_H
7+
8+
#include <mp/proxy-types.h>
9+
#include <mp/util.h>
10+
11+
namespace mp {
12+
template <typename KeyLocalType, typename ValueLocalType, typename Value, typename Output>
13+
void CustomBuildField(TypeList<std::map<KeyLocalType, ValueLocalType>>,
14+
Priority<1>,
15+
InvokeContext& invoke_context,
16+
Value&& value,
17+
Output&& output)
18+
{
19+
// FIXME dededup with vector handler above
20+
auto list = output.init(value.size());
21+
size_t i = 0;
22+
for (const auto& elem : value) {
23+
BuildField(TypeList<std::pair<KeyLocalType, ValueLocalType>>(), invoke_context,
24+
ListOutput<typename decltype(list)::Builds>(list, i), elem);
25+
++i;
26+
}
27+
}
28+
29+
template <typename KeyLocalType, typename ValueLocalType, typename Input, typename ReadDest>
30+
decltype(auto) CustomReadField(TypeList<std::map<KeyLocalType, ValueLocalType>>,
31+
Priority<1>,
32+
InvokeContext& invoke_context,
33+
Input&& input,
34+
ReadDest&& read_dest)
35+
{
36+
return read_dest.update([&](auto& value) {
37+
auto data = input.get();
38+
value.clear();
39+
for (auto item : data) {
40+
ReadField(TypeList<std::pair<const KeyLocalType, ValueLocalType>>(), invoke_context,
41+
Make<ValueField>(item),
42+
ReadDestEmplace(
43+
TypeList<std::pair<const KeyLocalType, ValueLocalType>>(), [&](auto&&... args) -> auto& {
44+
return *value.emplace(std::forward<decltype(args)>(args)...).first;
45+
}));
46+
}
47+
});
48+
}
49+
} // namespace mp
50+
51+
#endif // MP_PROXY_TYPE_MAP_H

test/mp/test/foo-types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <mp/proxy-types.h>
99
#include <mp/type-context.h>
10+
#include <mp/type-map.h>
1011
#include <mp/type-set.h>
1112
#include <mp/type-vector.h>
1213

0 commit comments

Comments
 (0)