Skip to content

Commit c6246c9

Browse files
committed
moveonly: add mp/type-vector.h
1 parent 619d2c7 commit c6246c9

File tree

4 files changed

+73
-57
lines changed

4 files changed

+73
-57
lines changed

CMakeLists.txt

+1
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-vector.h
5152
include/mp/util.h)
5253
add_library(multiprocess STATIC
5354
${MP_PROXY_SRCS}

include/mp/proxy-types.h

-57
Original file line numberDiff line numberDiff line change
@@ -144,43 +144,6 @@ struct ReadDestUpdate
144144

145145

146146

147-
template <typename LocalType, typename Input, typename ReadDest>
148-
decltype(auto) CustomReadField(TypeList<std::vector<LocalType>>,
149-
Priority<1>,
150-
InvokeContext& invoke_context,
151-
Input&& input,
152-
ReadDest&& read_dest)
153-
{
154-
return read_dest.update([&](auto& value) {
155-
auto data = input.get();
156-
value.clear();
157-
value.reserve(data.size());
158-
for (auto item : data) {
159-
ReadField(TypeList<LocalType>(), invoke_context, Make<ValueField>(item),
160-
ReadDestEmplace(TypeList<LocalType>(), [&](auto&&... args) -> auto& {
161-
value.emplace_back(std::forward<decltype(args)>(args)...);
162-
return value.back();
163-
}));
164-
}
165-
});
166-
}
167-
168-
template <typename Input, typename ReadDest>
169-
decltype(auto) CustomReadField(TypeList<std::vector<bool>>,
170-
Priority<1>,
171-
InvokeContext& invoke_context,
172-
Input&& input,
173-
ReadDest&& read_dest)
174-
{
175-
return read_dest.update([&](auto& value) {
176-
auto data = input.get();
177-
value.clear();
178-
value.reserve(data.size());
179-
for (auto item : data) {
180-
value.push_back(ReadField(TypeList<bool>(), invoke_context, Make<ValueField>(item), ReadDestTemp<bool>()));
181-
}
182-
});
183-
}
184147

185148
template <typename LocalType, typename Input, typename ReadDest>
186149
decltype(auto) CustomReadField(TypeList<std::set<LocalType>>,
@@ -635,21 +598,6 @@ struct ListOutput<::capnp::List<T, kind>>
635598
// clang-format on
636599
};
637600

638-
template <typename LocalType, typename Value, typename Output>
639-
void CustomBuildField(TypeList<std::vector<LocalType>>,
640-
Priority<1>,
641-
InvokeContext& invoke_context,
642-
Value&& value,
643-
Output&& output)
644-
{
645-
// FIXME dedup with set handler below
646-
auto list = output.init(value.size());
647-
size_t i = 0;
648-
for (auto it = value.begin(); it != value.end(); ++it, ++i) {
649-
BuildField(TypeList<LocalType>(), invoke_context, ListOutput<typename decltype(list)::Builds>(list, i), *it);
650-
}
651-
}
652-
653601
template <typename LocalType, typename Value, typename Output>
654602
void CustomBuildField(TypeList<std::set<LocalType>>,
655603
Priority<1>,
@@ -688,11 +636,6 @@ ::capnp::Void BuildPrimitive(InvokeContext& invoke_context, Value&&, TypeList<::
688636
return {};
689637
}
690638

691-
inline static bool BuildPrimitive(InvokeContext& invoke_context, std::vector<bool>::const_reference value, TypeList<bool>)
692-
{
693-
return value;
694-
}
695-
696639
template <typename LocalType, typename Value>
697640
LocalType BuildPrimitive(InvokeContext& invoke_context,
698641
const Value& value,

include/mp/type-vector.h

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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_VECTOR_H
6+
#define MP_PROXY_TYPE_VECTOR_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::vector<LocalType>>,
14+
Priority<1>,
15+
InvokeContext& invoke_context,
16+
Value&& value,
17+
Output&& output)
18+
{
19+
// FIXME dedup with set handler below
20+
auto list = output.init(value.size());
21+
size_t i = 0;
22+
for (auto it = value.begin(); it != value.end(); ++it, ++i) {
23+
BuildField(TypeList<LocalType>(), invoke_context, ListOutput<typename decltype(list)::Builds>(list, i), *it);
24+
}
25+
}
26+
27+
inline static bool BuildPrimitive(InvokeContext& invoke_context, std::vector<bool>::const_reference value, TypeList<bool>)
28+
{
29+
return value;
30+
}
31+
32+
template <typename LocalType, typename Input, typename ReadDest>
33+
decltype(auto) CustomReadField(TypeList<std::vector<LocalType>>,
34+
Priority<1>,
35+
InvokeContext& invoke_context,
36+
Input&& input,
37+
ReadDest&& read_dest)
38+
{
39+
return read_dest.update([&](auto& value) {
40+
auto data = input.get();
41+
value.clear();
42+
value.reserve(data.size());
43+
for (auto item : data) {
44+
ReadField(TypeList<LocalType>(), invoke_context, Make<ValueField>(item),
45+
ReadDestEmplace(TypeList<LocalType>(), [&](auto&&... args) -> auto& {
46+
value.emplace_back(std::forward<decltype(args)>(args)...);
47+
return value.back();
48+
}));
49+
}
50+
});
51+
}
52+
53+
template <typename Input, typename ReadDest>
54+
decltype(auto) CustomReadField(TypeList<std::vector<bool>>,
55+
Priority<1>,
56+
InvokeContext& invoke_context,
57+
Input&& input,
58+
ReadDest&& read_dest)
59+
{
60+
return read_dest.update([&](auto& value) {
61+
auto data = input.get();
62+
value.clear();
63+
value.reserve(data.size());
64+
for (auto item : data) {
65+
value.push_back(ReadField(TypeList<bool>(), invoke_context, Make<ValueField>(item), ReadDestTemp<bool>()));
66+
}
67+
});
68+
}
69+
} // namespace mp
70+
71+
#endif // MP_PROXY_TYPE_VECTOR_H

test/mp/test/foo-types.h

+1
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-vector.h>
1011

1112
namespace mp {
1213
namespace test {

0 commit comments

Comments
 (0)