Botan
3.11.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
template
<
typename
T0 = void,
typename
... Ts>
18
struct
all_same
{
19
static
constexpr
bool
value
= (std::is_same_v<T0, Ts> && ... &&
true
);
20
};
21
22
template
<
typename
... Ts>
23
static
constexpr
bool
all_same_v =
all_same
<Ts...>::value;
24
25
namespace
detail
{
26
27
/**
28
* Helper type to indicate that a certain type should be automatically
29
* detected based on the context.
30
*/
31
struct
AutoDetect
{
32
constexpr
AutoDetect
() =
delete
;
33
};
34
35
}
// namespace detail
36
37
namespace
concepts
{
38
39
// TODO: C++20 provides concepts like std::ranges::range or ::sized_range
40
// but at the time of this writing clang had not caught up on all
41
// platforms. E.g. clang 14 on Xcode does not support ranges properly.
42
43
template
<
typename
IterT,
typename
ContainerT>
44
concept
container_iterator
=
45
std::same_as<IterT, typename ContainerT::iterator> || std::same_as<IterT, typename ContainerT::const_iterator>;
46
47
template
<
typename
PtrT,
typename
ContainerT>
48
concept
container_pointer
=
49
std::same_as<PtrT, typename ContainerT::pointer> || std::same_as<PtrT, typename ContainerT::const_pointer>;
50
51
template
<
typename
T>
52
concept
container
=
requires
(T a) {
53
{ a.begin() } ->
container_iterator<T>
;
54
{ a.end() } ->
container_iterator<T>
;
55
{ a.cbegin() } ->
container_iterator<T>
;
56
{ a.cend() } ->
container_iterator<T>
;
57
{ a.size() } -> std::same_as<typename T::size_type>;
58
typename
T::value_type;
59
};
60
61
template
<
typename
T>
62
concept
contiguous_container
=
container<T>
&&
requires
(T a) {
63
{ a.data() } ->
container_pointer<T>
;
64
};
65
66
template
<
typename
T>
67
concept
has_empty
=
requires
(T a) {
68
{ a.empty() } -> std::same_as<bool>;
69
};
70
71
template
<
typename
T>
72
concept
resizable_container
=
container<T>
&&
requires
(T& c,
typename
T::size_type s) {
73
T(s);
74
c.resize(s);
75
};
76
77
template
<
typename
T>
78
concept
reservable_container
=
container<T>
&&
requires
(T& c,
typename
T::size_type s) { c.reserve(s); };
79
80
template
<
typename
T>
81
concept
resizable_byte_buffer
=
82
contiguous_container<T>
&&
resizable_container<T>
&& std::same_as<typename T::value_type, uint8_t>;
83
84
}
// namespace concepts
85
86
}
// namespace Botan
87
88
#endif
Botan::concepts::container_iterator
Definition
concepts.h:44
Botan::concepts::container_pointer
Definition
concepts.h:48
Botan::concepts::container
Definition
concepts.h:52
Botan::concepts::contiguous_container
Definition
concepts.h:62
Botan::concepts::has_empty
Definition
concepts.h:67
Botan::concepts::reservable_container
Definition
concepts.h:78
Botan::concepts::resizable_byte_buffer
Definition
concepts.h:81
Botan::concepts::resizable_container
Definition
concepts.h:72
Botan::concepts
Definition
concepts.h:37
Botan::detail
Definition
sponge_processing.h:22
Botan
Definition
alg_id.cpp:13
Botan::all_same
Definition
concepts.h:18
Botan::all_same::value
static constexpr bool value
Definition
concepts.h:19
Botan::detail::AutoDetect::AutoDetect
constexpr AutoDetect()=delete
Generated by
1.15.0