xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
protocol
Concepts.h
1
#pragma once
2
3
#include <xrpl/protocol/UintTypes.h>
4
5
#include <
type_traits
>
6
7
namespace
xrpl
{
8
9
class
STAmount
;
10
class
Asset
;
11
class
Issue
;
12
class
MPTIssue
;
13
class
IOUAmount
;
14
class
XRPAmount
;
15
class
MPTAmount
;
16
17
template
<
typename
A>
18
concept
StepAmount
=
19
std::is_same_v<A, XRPAmount>
||
std::is_same_v<A, IOUAmount>
||
std::is_same_v<A, MPTAmount>
;
20
21
template
<
typename
TIss>
22
concept
ValidIssueType
=
std::is_same_v<TIss, Issue>
||
std::is_same_v<TIss, MPTIssue>
;
23
24
template
<
typename
A>
25
concept
AssetType
=
std::is_convertible_v<A, Asset>
||
std::is_convertible_v<A, Issue>
||
26
std::is_convertible_v<A, MPTIssue>
||
std::is_convertible_v<A, MPTID>
;
27
28
template
<
typename
T>
29
concept
ValidPathAsset
= (
std::is_same_v<T, Currency>
||
std::is_same_v<T, MPTID>
);
30
31
template
<
class
TTakerPays,
class
TTakerGets>
32
concept
ValidTaker
=
33
((
std::is_same_v<TTakerPays, IOUAmount>
||
std::is_same_v<TTakerPays, XRPAmount>
||
34
std::is_same_v<TTakerPays, MPTAmount>
) &&
35
(
std::is_same_v<TTakerGets, IOUAmount>
||
std::is_same_v<TTakerGets, XRPAmount>
||
36
std::is_same_v<TTakerGets, MPTAmount>
) &&
37
(!
std::is_same_v<TTakerPays, XRPAmount>
|| !
std::is_same_v<TTakerGets, XRPAmount>
));
38
39
namespace
detail
{
40
41
// This template combines multiple callable objects (lambdas) into a single
42
// object that std::visit can use for overload resolution.
43
template
<
typename
... Ts>
44
struct
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.
60
template
<
typename
... Ts>
61
constexpr
CombineVisitors<std::decay_t<Ts>...>
62
makeCombineVisitors
(Ts&&... 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.
67
return
CombineVisitors<std::decay_t<Ts>
...>{
std::forward<Ts>
(ts)...};
68
}
69
70
// This function takes ANY variant and ANY number of visitors, and performs the
71
// visit. It is the reusable core logic.
72
template
<
typename
Variant,
typename
... Visitors>
73
constexpr
auto
74
visit
(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
xrpl::Asset
Definition
Asset.h:52
xrpl::IOUAmount
Floating point representation of amounts with high dynamic range.
Definition
IOUAmount.h:26
xrpl::Issue
A currency issued by an account.
Definition
Issue.h:18
xrpl::MPTAmount
Definition
MPTAmount.h:23
xrpl::MPTIssue
Definition
MPTIssue.h:23
xrpl::STAmount
Definition
STAmount.h:46
xrpl::XRPAmount
Definition
XRPAmount.h:28
xrpl::AssetType
Definition
Concepts.h:25
xrpl::StepAmount
Definition
Concepts.h:18
xrpl::ValidIssueType
Definition
Concepts.h:22
xrpl::ValidPathAsset
Definition
Concepts.h:29
xrpl::ValidTaker
Definition
Concepts.h:32
std::forward
T forward(T... args)
std::is_convertible_v
T is_convertible_v
std::is_same_v
T is_same_v
std
STL namespace.
xrpl::detail
Definition
base_uint.h:37
xrpl::detail::makeCombineVisitors
constexpr CombineVisitors< std::decay_t< Ts >... > makeCombineVisitors(Ts &&... ts)
Definition
Concepts.h:62
xrpl::detail::visit
constexpr auto visit(Variant &&v, Visitors &&... visitors) -> decltype(auto)
Definition
Concepts.h:74
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::detail::CombineVisitors
Definition
Concepts.h:45
xrpl::detail::CombineVisitors::CombineVisitors
constexpr CombineVisitors(Ts &&... ts)
Definition
Concepts.h:53
type_traits
std::visit
T visit(T... args)
Generated by
1.17.0