Botan
3.13.0
Crypto and TLS for C&
src
lib
utils
concepts.h
Go to the documentation of this file.
1
/**
2
* Useful concepts that are available throughout the library
3
* (C) 2023 Jack Lloyd
4
* 2023 René Meusel - Rohde & Schwarz Cybersecurity
5
*
6
* Botan is released under the Simplified BSD License (see license.txt)
7
*/
8
9
#ifndef BOTAN_CONCEPTS_H_
10
#define BOTAN_CONCEPTS_H_
11
12
#include <botan/types.h>
13
#include <concepts>
14
15
namespace
Botan
{
16
17
/**
18
* Trait that checks whether all of the given types are the same type
19
*/
20
template
<
typename
T0 = void,
typename
... Ts>
21
struct
all_same
{
22
/// True if every type in Ts is the same as T0
23
static
constexpr
bool
value
= (std::is_same_v<T0, Ts> && ... &&
true
);
24
};
25
26
template
<
typename
... Ts>
27
static
constexpr
bool
all_same_v =
all_same
<Ts...>::value;
28
29
namespace
detail
{
30
31
/**
32
* Helper type to indicate that a certain type should be automatically
33
* detected based on the context.
34
*/
35
struct
AutoDetect
{
36
/// This type is a tag only and cannot be instantiated
37
constexpr
AutoDetect
() =
delete
;
38
};
39
40
}
// namespace detail
41
42
namespace
concepts
{
43
44
// TODO: C++20 provides concepts like std::ranges::range or ::sized_range
45
// but at the time of this writing clang had not caught up on all
46
// platforms. E.g. clang 14 on Xcode does not support ranges properly.
47
48
template
<
typename
IterT,
typename
ContainerT>
49
concept
container_iterator
=
50
std::same_as<IterT, typename ContainerT::iterator> || std::same_as<IterT, typename ContainerT::const_iterator>;
51
52
template
<
typename
PtrT,
typename
ContainerT>
53
concept
container_pointer
=
54
std::same_as<PtrT, typename ContainerT::pointer> || std::same_as<PtrT, typename ContainerT::const_pointer>;
55
56
template
<
typename
T>
57
concept
container
=
requires
(T a) {
58
{ a.begin() } ->
container_iterator<T>
;
59
{ a.end() } ->
container_iterator<T>
;
60
{ a.cbegin() } ->
container_iterator<T>
;
61
{ a.cend() } ->
container_iterator<T>
;
62
{ a.size() } -> std::same_as<typename T::size_type>;
63
typename
T::value_type;
64
};
65
66
template
<
typename
T>
67
concept
contiguous_container
=
container<T>
&&
requires
(T a) {
68
{ a.data() } ->
container_pointer<T>
;
69
};
70
71
template
<
typename
T>
72
concept
has_empty
=
requires
(T a) {
73
{ a.empty() } -> std::same_as<bool>;
74
};
75
76
template
<
typename
T>
77
concept
resizable_container
=
container<T>
&&
requires
(T& c,
typename
T::size_type s) {
78
T(s);
79
c.resize(s);
80
};
81
82
template
<
typename
T>
83
concept
reservable_container
=
container<T>
&&
requires
(T& c,
typename
T::size_type s) { c.reserve(s); };
84
85
template
<
typename
T>
86
concept
resizable_byte_buffer
=
87
contiguous_container<T>
&&
resizable_container<T>
&& std::same_as<typename T::value_type, uint8_t>;
88
89
}
// namespace concepts
90
91
}
// namespace Botan
92
93
#endif
Botan::concepts::container_iterator
Definition
concepts.h:49
Botan::concepts::container_pointer
Definition
concepts.h:53
Botan::concepts::container
Definition
concepts.h:57
Botan::concepts::contiguous_container
Definition
concepts.h:67
Botan::concepts::has_empty
Definition
concepts.h:72
Botan::concepts::reservable_container
Definition
concepts.h:83
Botan::concepts::resizable_byte_buffer
Definition
concepts.h:86
Botan::concepts::resizable_container
Definition
concepts.h:77
Botan::concepts
Definition
concepts.h:42
Botan::detail
Definition
sponge_processing.h:22
Botan
Definition
alg_id.cpp:14
Botan::all_same
Definition
concepts.h:21
Botan::all_same::value
static constexpr bool value
True if every type in Ts is the same as T0.
Definition
concepts.h:23
Botan::detail::AutoDetect::AutoDetect
constexpr AutoDetect()=delete
This type is a tag only and cannot be instantiated.
Generated by
1.16.1