-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathtype_traits.hpp
More file actions
133 lines (105 loc) · 3.07 KB
/
Copy pathtype_traits.hpp
File metadata and controls
133 lines (105 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
// Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/boostorg/url
//
#ifndef BOOST_URL_GRAMMAR_TYPE_TRAITS_HPP
#define BOOST_URL_GRAMMAR_TYPE_TRAITS_HPP
#include <boost/url/detail/config.hpp>
#include <boost/url/error_types.hpp>
#include <type_traits>
namespace boost {
namespace urls {
namespace grammar {
namespace implementation_defined
{
template<class T, class = void>
struct is_rule : std::false_type {};
template<class T>
struct is_rule<T, void_t<decltype(
std::declval<system::result<typename T::value_type>&>() =
std::declval<T const&>().parse(
std::declval<char const*&>(),
std::declval<char const*>())
)>> : std::is_nothrow_copy_constructible<T>
{
};
}
/** Determine if T meets the requirements of @ref Rule
This is an alias for `std::true_type` if
`T` meets the requirements, otherwise it
is an alias for `std::false_type`.
@par Example
@code
struct U
{
struct value_type;
auto
parse(
char const*& it,
char const* end) const ->
system::result<value_type>
};
static_assert( is_rule<U>::value, "Requirements not met" );
@endcode
@see
@ref parse.
*/
template<class T>
using is_rule = implementation_defined::is_rule<T>;
#ifdef BOOST_URL_HAS_CONCEPTS
/** Concept for a grammar Rule
This concept is satisfied if `T` is a
valid grammar Rule
A `Rule` defines an algorithm used to match an input
buffer of ASCII characters against a set of syntactical
specifications.
Each rule represents either a terminal symbol or a
composition in the represented grammar.
The library comes with a set of rules for productions
typically found in RFC documents.
Rules are not invoked directly; instead, rule variables are
used with overloads of @ref parse which provide a convenient,
uniform front end.
@par Exemplar
For best results, it is suggested that all constructors for
rules be marked `constexpr`.
@code
struct Rule
{
struct value_type;
constexpr Rule( Rule const& ) noexcept = default;
auto parse( char const*& it, char const* end ) const -> result< value_type >;
};
// Declare a variable of type Rule for notational convenience
constexpr Rule rule{};
@endcode
@par Model
@li @ref dec_octet_rule
@li @ref delim_rule
@li @ref not_empty_rule
@li @ref optional_rule
@li @ref range_rule
@li @ref token_rule
@li @ref tuple_rule
@li @ref unsigned_rule
@li @ref variant_rule
@see
@ref parse,
@ref is_rule.
*/
template <class T>
concept Rule =
requires (T t, char const*& it, char const* end)
{
typename T::value_type;
{ t.parse(it, end) } -> std::same_as<system::result<typename T::value_type>>;
};
#endif
} // grammar
} // urls
} // boost
#endif