xrpld
Loading...
Searching...
No Matches
Concepts.h
1#pragma once
2
3#include <xrpl/protocol/UintTypes.h>
4
5#include <type_traits>
6
7namespace xrpl {
8
9class STAmount;
10class Asset;
11class Issue;
12class MPTIssue;
13class IOUAmount;
14class XRPAmount;
15class MPTAmount;
16
17template <typename A>
18concept StepAmount =
20
21template <typename TIss>
23
24template <typename A>
27
28template <typename T>
30
31template <class TTakerPays, class TTakerGets>
32concept ValidTaker =
38
39namespace detail {
40
41// This template combines multiple callable objects (lambdas) into a single
42// object that std::visit can use for overload resolution.
43template <typename... Ts>
44struct CombineVisitors : Ts...
45{
46 // Bring all operator() overloads from base classes into this scope.
47 // It's the mechanism that makes the CombineVisitors struct function
48 // as a single callable object with multiple overloads.
49 using Ts::operator()...;
50
51 // Perfect forwarding constructor to correctly initialize the base class
52 // lambdas
53 constexpr CombineVisitors(Ts&&... ts) : Ts(std::forward<Ts>(ts))...
54 {
55 }
56};
57
58// This function forces function template argument deduction, which is more
59// robust than class template argument deduction (CTAD) via the deduction guide.
60template <typename... Ts>
61constexpr CombineVisitors<std::decay_t<Ts>...>
63{
64 // std::decay_t<Ts> is used to remove references/constness from the lambda
65 // types before they are passed as template arguments to the CombineVisitors
66 // struct.
68}
69
70// This function takes ANY variant and ANY number of visitors, and performs the
71// visit. It is the reusable core logic.
72template <typename Variant, typename... Visitors>
73constexpr auto
74visit(Variant&& v, Visitors&&... visitors) -> decltype(auto)
75{
76 // Use the function template helper instead of raw CTAD.
77 auto visitorSet = makeCombineVisitors(std::forward<Visitors>(visitors)...);
78
79 // Delegate to std::visit, perfectly forwarding the variant and the visitor
80 // set.
81 return std::visit(visitorSet, std::forward<Variant>(v));
82}
83
84} // namespace detail
85
86} // namespace xrpl
Floating point representation of amounts with high dynamic range.
Definition IOUAmount.h:24
A currency issued by an account.
Definition Issue.h:13
T forward(T... args)
T is_convertible_v
T is_same_v
STL namespace.
constexpr CombineVisitors< std::decay_t< Ts >... > makeCombineVisitors(Ts &&... ts)
Definition Concepts.h:62
constexpr auto visit(Variant &&v, Visitors &&... visitors) -> decltype(auto)
Definition Concepts.h:74
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
constexpr CombineVisitors(Ts &&... ts)
Definition Concepts.h:53
T visit(T... args)