Branch data 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_OPTIONAL_H
6 : : #define MP_PROXY_TYPE_OPTIONAL_H
7 : :
8 : : #include <mp/util.h>
9 : :
10 : : namespace mp {
11 : : template <typename LocalType, typename Value, typename Output>
12 [ # # ]: 0 : void CustomBuildField(TypeList<std::optional<LocalType>>,
13 : : Priority<1>,
14 : : InvokeContext& invoke_context,
15 : : Value&& value,
16 : : Output&& output)
17 : : {
18 [ # # ]: 0 : if (value) {
19 : 0 : output.setHas();
20 : : // FIXME: should std::move value if destvalue is rref?
21 : 0 : BuildField(TypeList<LocalType>(), invoke_context, output, *value);
22 : : }
23 : 0 : }
24 : :
25 : : template <typename LocalType, typename Input, typename ReadDest>
26 : 0 : decltype(auto) CustomReadField(TypeList<std::optional<LocalType>>,
27 : : Priority<1>,
28 : : InvokeContext& invoke_context,
29 : : Input&& input,
30 : : ReadDest&& read_dest)
31 : : {
32 : 0 : return read_dest.update([&](auto& value) {
33 [ # # # # : 0 : if (!input.has()) {
# # # # ]
34 : 0 : value.reset();
35 [ # # # # ]: 0 : } else if (value) {
36 : 0 : ReadField(TypeList<LocalType>(), invoke_context, input, ReadDestUpdate(*value));
37 : : } else {
38 : 0 : ReadField(TypeList<LocalType>(), invoke_context, input,
39 : 0 : ReadDestEmplace(TypeList<LocalType>(), [&](auto&&... args) -> auto& {
40 : 0 : value.emplace(std::forward<decltype(args)>(args)...);
41 : 0 : return *value;
42 : : }));
43 : : }
44 : 0 : });
45 : : }
46 : : } // namespace mp
47 : :
48 : : #endif // MP_PROXY_TYPE_OPTIONAL_H
|