Skip to content

Commit 6a68472

Browse files
committed
moveonly: add mp/type-set.h
1 parent c6246c9 commit 6a68472

File tree

4 files changed

+50
-35
lines changed

4 files changed

+50
-35
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ set(MP_PUBLIC_HEADERS
4848
include/mp/type-context.h
4949
include/mp/type-optional.h
5050
include/mp/type-pointer.h
51+
include/mp/type-set.h
5152
include/mp/type-vector.h
5253
include/mp/util.h)
5354
add_library(multiprocess STATIC

include/mp/proxy-types.h

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -145,25 +145,6 @@ struct ReadDestUpdate
145145

146146

147147

148-
template <typename LocalType, typename Input, typename ReadDest>
149-
decltype(auto) CustomReadField(TypeList<std::set<LocalType>>,
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<LocalType>(), invoke_context, Make<ValueField>(item),
160-
ReadDestEmplace(TypeList<const LocalType>(), [&](auto&&... args) -> auto& {
161-
return *value.emplace(std::forward<decltype(args)>(args)...).first;
162-
}));
163-
}
164-
});
165-
}
166-
167148
template <typename KeyLocalType, typename ValueLocalType, typename Input, typename ReadDest>
168149
decltype(auto) CustomReadField(TypeList<std::map<KeyLocalType, ValueLocalType>>,
169150
Priority<1>,
@@ -598,22 +579,6 @@ struct ListOutput<::capnp::List<T, kind>>
598579
// clang-format on
599580
};
600581

601-
template <typename LocalType, typename Value, typename Output>
602-
void CustomBuildField(TypeList<std::set<LocalType>>,
603-
Priority<1>,
604-
InvokeContext& invoke_context,
605-
Value&& value,
606-
Output&& output)
607-
{
608-
// FIXME dededup with vector handler above
609-
auto list = output.init(value.size());
610-
size_t i = 0;
611-
for (const auto& elem : value) {
612-
BuildField(TypeList<LocalType>(), invoke_context, ListOutput<typename decltype(list)::Builds>(list, i), elem);
613-
++i;
614-
}
615-
}
616-
617582
template <typename KeyLocalType, typename ValueLocalType, typename Value, typename Output>
618583
void CustomBuildField(TypeList<std::map<KeyLocalType, ValueLocalType>>,
619584
Priority<1>,

include/mp/type-set.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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_SET_H
6+
#define MP_PROXY_TYPE_SET_H
7+
8+
#include <mp/proxy-types.h>
9+
#include <mp/util.h>
10+
11+
namespace mp {
12+
template <typename LocalType, typename Value, typename Output>
13+
void CustomBuildField(TypeList<std::set<LocalType>>,
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<LocalType>(), invoke_context, ListOutput<typename decltype(list)::Builds>(list, i), elem);
24+
++i;
25+
}
26+
}
27+
28+
template <typename LocalType, typename Input, typename ReadDest>
29+
decltype(auto) CustomReadField(TypeList<std::set<LocalType>>,
30+
Priority<1>,
31+
InvokeContext& invoke_context,
32+
Input&& input,
33+
ReadDest&& read_dest)
34+
{
35+
return read_dest.update([&](auto& value) {
36+
auto data = input.get();
37+
value.clear();
38+
for (auto item : data) {
39+
ReadField(TypeList<LocalType>(), invoke_context, Make<ValueField>(item),
40+
ReadDestEmplace(TypeList<const LocalType>(), [&](auto&&... args) -> auto& {
41+
return *value.emplace(std::forward<decltype(args)>(args)...).first;
42+
}));
43+
}
44+
});
45+
}
46+
} // namespace mp
47+
48+
#endif // MP_PROXY_TYPE_SET_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-set.h>
1011
#include <mp/type-vector.h>
1112

1213
namespace mp {

0 commit comments

Comments
 (0)