Bitcoin Core 32.99.0
P2P Digital Currency
Loading...
Searching...
No Matches
type-map.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_MAP_H
6#define MP_PROXY_TYPE_MAP_H
7
8#include <mp/proxy-types.h>
9#include <mp/type-pair.h>
10#include <mp/util.h>
11
12#include <map>
13
14namespace mp {
15template <typename KeyLocalType, typename ValueLocalType, typename Compare, typename Allocator, typename Value, typename Output>
16void CustomBuildField(TypeList<std::map<KeyLocalType, ValueLocalType, Compare, Allocator>>,
19 Value&& value,
20 Output&& output)
21{
22 BuildList(TypeList<std::pair<KeyLocalType, ValueLocalType>>(), invoke_context, output, value);
23}
24
25// Replacement for `m.emplace(piecewise_construct, t1, t2)` to work around a
26// Clang 22 regression triggered by libc++'s std::map piecewise emplace: when
27// the key constructor argument tuple is empty (std::tuple<>), libc++'s internal
28// "try key extraction" SFINAE probe instantiates std::tuple_element<0,
29// std::tuple<>>, which Clang 22 diagnoses as an out-of-bounds pack access ("a
30// parameter pack may not be accessed at an out of bounds index") instead of
31// treating it as substitution failure. See LLVM issue #167709 and the upstream
32// fix in llvm/llvm-project PR #183614.
33// https://github.com/llvm/llvm-project/issues/167709
34// https://github.com/llvm/llvm-project/pull/183614
35template <class Map, class Tuple1, class Tuple2>
37 Map& m,
38 const std::piecewise_construct_t&,
39 Tuple1&& t1,
40 Tuple2&& t2)
41{
42 if constexpr (std::tuple_size_v<std::remove_reference_t<Tuple1>> == 0) {
43 // Avoid tuple<> / tuple<> (LLVM 22 libc++ regression path)
44 return m.emplace(std::piecewise_construct,
45 std::forward_as_tuple(typename Map::key_type{}),
46 std::forward<Tuple2>(t2));
47 } else {
48 return m.emplace(std::piecewise_construct,
49 std::forward<Tuple1>(t1),
50 std::forward<Tuple2>(t2));
51 }
52}
53
54template <typename KeyLocalType, typename ValueLocalType, typename Compare, typename Allocator, typename Input, typename ReadDest>
55decltype(auto) CustomReadField(TypeList<std::map<KeyLocalType, ValueLocalType, Compare, Allocator>>,
58 Input&& input,
60{
61 return ReadList(
62 TypeList<std::pair<const KeyLocalType, ValueLocalType>>(), invoke_context, input, read_dest,
63 [&](auto& value, size_t) { value.clear(); },
64 [&](auto& value, auto&&... args) -> auto& {
65 return *EmplacePiecewiseSafe(value, std::forward<decltype(args)>(args)...).first;
66 });
67}
68} // namespace mp
69
70#endif // MP_PROXY_TYPE_MAP_H
ArgsManager & args
Definition bitcoind.cpp:280
Functions to serialize / deserialize common bitcoin types.
void BuildList(TypeList< LocalType >, InvokeContext &invoke_context, Output &&output, Value &&value)
auto EmplacePiecewiseSafe(Map &m, const std::piecewise_construct_t &, Tuple1 &&t1, Tuple2 &&t2)
Definition type-map.h:36
decltype(auto) CustomReadField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Input &&input, ReadDest &&read_dest)
Overload multiprocess library's CustomReadField hook to allow any object with an Unserialize method t...
decltype(auto) ReadList(TypeList< LocalType >, InvokeContext &invoke_context, Input &&input, ReadDest &&read_dest, InitFn &&init, EmplaceFn &&emplace)
void CustomBuildField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Value &&value, Output &&output)
Overload multiprocess library's CustomBuildField hook to allow any serializable object to be stored i...
Function parameter type for prioritizing overloaded function calls that would otherwise be ambiguous.
Definition util.h:143
Type holding a list of types.
Definition util.h:57
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:82