Line data Source code
1 : // Copyright (c) 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_PAIR_H
6 : #define MP_PROXY_TYPE_PAIR_H
7 :
8 : #include <mp/util.h>
9 :
10 : namespace mp {
11 : // FIXME: Overload on output type instead of value type and switch to std::get and merge with next overload
12 : template <typename KeyLocalType, typename ValueLocalType, typename Value, typename Output>
13 0 : void CustomBuildField(TypeList<std::pair<KeyLocalType, ValueLocalType>>,
14 : Priority<1>,
15 : InvokeContext& invoke_context,
16 : Value&& value,
17 : Output&& output)
18 : {
19 0 : auto pair = output.init();
20 : using Accessors = typename ProxyStruct<typename decltype(pair)::Builds>::Accessors;
21 0 : BuildField(TypeList<KeyLocalType>(), invoke_context, Make<StructField, std::tuple_element_t<0, Accessors>>(pair), value.first);
22 0 : BuildField(TypeList<ValueLocalType>(), invoke_context, Make<StructField, std::tuple_element_t<1, Accessors>>(pair), value.second);
23 0 : }
24 :
25 : template <typename KeyLocalType, typename ValueLocalType, typename Input, typename ReadDest>
26 0 : decltype(auto) CustomReadField(TypeList<std::pair<KeyLocalType, ValueLocalType>>,
27 : Priority<1>,
28 : InvokeContext& invoke_context,
29 : Input&& input,
30 : ReadDest&& read_dest)
31 : {
32 0 : const auto& pair = input.get();
33 : using Accessors = typename ProxyStruct<typename Decay<decltype(pair)>::Reads>::Accessors;
34 :
35 0 : ReadField(TypeList<KeyLocalType>(), invoke_context, Make<StructField, std::tuple_element_t<0, Accessors>>(pair),
36 0 : ReadDestEmplace(TypeList<KeyLocalType>(), [&](auto&&... key_args) -> auto& {
37 0 : KeyLocalType* key = nullptr;
38 0 : ReadField(TypeList<ValueLocalType>(), invoke_context, Make<StructField, std::tuple_element_t<1, Accessors>>(pair),
39 0 : ReadDestEmplace(TypeList<ValueLocalType>(), [&](auto&&... value_args) -> auto& {
40 0 : auto& ret = read_dest.construct(std::piecewise_construct, std::forward_as_tuple(key_args...),
41 0 : std::forward_as_tuple(value_args...));
42 0 : key = &ret.first;
43 0 : return ret.second;
44 : }));
45 0 : return *key;
46 : }));
47 0 : }
48 : } // namespace mp
49 :
50 : #endif // MP_PROXY_TYPE_PAIR_H
|