Bitcoin Core  31.0.0
P2P Digital Currency
type-pair.h
Go to the documentation of this file.
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 void CustomBuildField(TypeList<std::pair<KeyLocalType, ValueLocalType>>,
15  InvokeContext& invoke_context,
16  Value&& value,
17  Output&& output)
18 {
19  auto pair = output.init();
21  BuildField(TypeList<KeyLocalType>(), invoke_context, Make<StructField, std::tuple_element_t<0, Accessors>>(pair), value.first);
22  BuildField(TypeList<ValueLocalType>(), invoke_context, Make<StructField, std::tuple_element_t<1, Accessors>>(pair), value.second);
23 }
24 
25 template <typename KeyLocalType, typename ValueLocalType, typename Input, typename ReadDest>
26 decltype(auto) CustomReadField(TypeList<std::pair<KeyLocalType, ValueLocalType>>,
27  Priority<1>,
28  InvokeContext& invoke_context,
29  Input&& input,
30  ReadDest&& read_dest)
31 {
32  const auto& pair = input.get();
33  using Accessors = typename ProxyStruct<typename Decay<decltype(pair)>::Reads>::Accessors;
34 
35  ReadField(TypeList<KeyLocalType>(), invoke_context, Make<StructField, std::tuple_element_t<0, Accessors>>(pair),
36  ReadDestEmplace(TypeList<KeyLocalType>(), [&](auto&&... key_args) -> auto& {
37  KeyLocalType* key = nullptr;
38  ReadField(TypeList<ValueLocalType>(), invoke_context, Make<StructField, std::tuple_element_t<1, Accessors>>(pair),
39  ReadDestEmplace(TypeList<ValueLocalType>(), [&](auto&&... value_args) -> auto& {
40  auto& ret = read_dest.construct(std::piecewise_construct, std::forward_as_tuple(key_args...),
41  std::forward_as_tuple(value_args...));
42  key = &ret.first;
43  return ret.second;
44  }));
45  return *key;
46  }));
47 }
48 } // namespace mp
49 
50 #endif // MP_PROXY_TYPE_PAIR_H
int ret
Function parameter type for prioritizing overloaded function calls that would otherwise be ambiguous...
Definition: util.h:108
Definition: common.h:29
Generic utility functions used by capnp code.
Definition: util.h:32
Functions to serialize / deserialize common bitcoin types.
Definition: common-types.h:57
Mapping from capnp struct type to struct traits (specializations are generated by proxy-codegen...
Definition: proxy.h:32
void BuildField(TypeList< LocalTypes... >, Context &context, Output &&output, Values &&... values)
Definition: proxy-types.h:250
decltype(auto) CustomReadField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Input &&input, ReadDest &&read_dest) requires Unserializable< LocalType
Overload multiprocess library&#39;s CustomReadField hook to allow any object with an Unserialize method t...
Definition: common-types.h:100
void CustomBuildField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Value &&value, Output &&output) requires Serializable< LocalType
Overload multiprocess library&#39;s CustomBuildField hook to allow any serializable object to be stored i...
decltype(auto) ReadField(TypeList< LocalTypes... >, InvokeContext &invoke_context, Input &&input, Args &&... args)
Definition: proxy-types.h:213
Class< Types..., std::remove_reference_t< Args >... > Make(Args &&... args)
Construct a template class value by deducing template arguments from the types of constructor argumen...
Definition: util.h:46