Skip to content

Commit 6d831eb

Browse files
committed
moveonly: add mp/type-tuple.h
1 parent c999100 commit 6d831eb

File tree

3 files changed

+46
-36
lines changed

3 files changed

+46
-36
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ set(MP_PUBLIC_HEADERS
5151
include/mp/type-pair.h
5252
include/mp/type-pointer.h
5353
include/mp/type-set.h
54+
include/mp/type-tuple.h
5455
include/mp/type-vector.h
5556
include/mp/util.h)
5657
add_library(multiprocess STATIC

include/mp/proxy-types.h

-36
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,6 @@ struct ReadDestUpdate
141141
Value& m_value;
142142
};
143143

144-
145-
146-
147-
// TODO: Should generalize this to work with arbitrary length tuples, not just length 2-tuples.
148-
template <typename KeyLocalType, typename ValueLocalType, typename Input, typename ReadDest>
149-
decltype(auto) CustomReadField(TypeList<std::tuple<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-
const auto& pair = input.get();
157-
using Struct = ProxyStruct<typename Decay<decltype(pair)>::Reads>;
158-
using Accessors = typename Struct::Accessors;
159-
ReadField(TypeList<KeyLocalType>(), invoke_context, Make<StructField, std::tuple_element_t<0, Accessors>>(pair),
160-
ReadDestUpdate(std::get<0>(value)));
161-
ReadField(TypeList<ValueLocalType>(), invoke_context, Make<StructField, std::tuple_element_t<1, Accessors>>(pair),
162-
ReadDestUpdate(std::get<1>(value)));
163-
});
164-
}
165-
166144
template <typename LocalType, typename Input, typename ReadDest>
167145
decltype(auto) CustomReadField(TypeList<LocalType>,
168146
Priority<1>,
@@ -584,20 +562,6 @@ void CustomBuildField(TypeList<std::exception>,
584562
{
585563
BuildField(TypeList<std::string>(), invoke_context, output, std::string(value.what()));
586564
}
587-
// TODO: Should generalize this to work with arbitrary length tuples, not just length 2-tuples.
588-
template <typename KeyLocalType, typename ValueLocalType, typename Value, typename Output>
589-
void CustomBuildField(TypeList<std::tuple<KeyLocalType, ValueLocalType>>,
590-
Priority<1>,
591-
InvokeContext& invoke_context,
592-
Value&& value,
593-
Output&& output)
594-
{
595-
auto pair = output.init();
596-
using Accessors = typename ProxyStruct<typename decltype(pair)::Builds>::Accessors;
597-
BuildField(TypeList<KeyLocalType>(), invoke_context, Make<StructField, std::tuple_element_t<0, Accessors>>(pair), std::get<0>(value));
598-
BuildField(TypeList<ValueLocalType>(), invoke_context, Make<StructField, std::tuple_element_t<1, Accessors>>(pair), std::get<1>(value));
599-
}
600-
601565
template <typename LocalType, typename Value, typename Output>
602566
void CustomBuildField(TypeList<const LocalType>,
603567
Priority<0>,

include/mp/type-tuple.h

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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_TUPLE_H
6+
#define MP_PROXY_TYPE_TUPLE_H
7+
8+
#include <mp/util.h>
9+
10+
namespace mp {
11+
// TODO: Should generalize this to work with arbitrary length tuples, not just length 2-tuples.
12+
template <typename KeyLocalType, typename ValueLocalType, typename Value, typename Output>
13+
void CustomBuildField(TypeList<std::tuple<KeyLocalType, ValueLocalType>>,
14+
Priority<1>,
15+
InvokeContext& invoke_context,
16+
Value&& value,
17+
Output&& output)
18+
{
19+
auto pair = output.init();
20+
using Accessors = typename ProxyStruct<typename decltype(pair)::Builds>::Accessors;
21+
BuildField(TypeList<KeyLocalType>(), invoke_context, Make<StructField, std::tuple_element_t<0, Accessors>>(pair), std::get<0>(value));
22+
BuildField(TypeList<ValueLocalType>(), invoke_context, Make<StructField, std::tuple_element_t<1, Accessors>>(pair), std::get<1>(value));
23+
}
24+
25+
// TODO: Should generalize this to work with arbitrary length tuples, not just length 2-tuples.
26+
template <typename KeyLocalType, typename ValueLocalType, typename Input, typename ReadDest>
27+
decltype(auto) CustomReadField(TypeList<std::tuple<KeyLocalType, ValueLocalType>>,
28+
Priority<1>,
29+
InvokeContext& invoke_context,
30+
Input&& input,
31+
ReadDest&& read_dest)
32+
{
33+
return read_dest.update([&](auto& value) {
34+
const auto& pair = input.get();
35+
using Struct = ProxyStruct<typename Decay<decltype(pair)>::Reads>;
36+
using Accessors = typename Struct::Accessors;
37+
ReadField(TypeList<KeyLocalType>(), invoke_context, Make<StructField, std::tuple_element_t<0, Accessors>>(pair),
38+
ReadDestUpdate(std::get<0>(value)));
39+
ReadField(TypeList<ValueLocalType>(), invoke_context, Make<StructField, std::tuple_element_t<1, Accessors>>(pair),
40+
ReadDestUpdate(std::get<1>(value)));
41+
});
42+
}
43+
} // namespace mp
44+
45+
#endif // MP_PROXY_TYPE_TUPLE_H

0 commit comments

Comments
 (0)