Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:52:41

0001 //
0002 // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/url
0008 //
0009 
0010 #ifndef BOOST_URL_GRAMMAR_TYPE_TRAITS_HPP
0011 #define BOOST_URL_GRAMMAR_TYPE_TRAITS_HPP
0012 
0013 #include <boost/url/detail/config.hpp>
0014 #include <boost/url/error_types.hpp>
0015 #include <type_traits>
0016 
0017 namespace boost {
0018 namespace urls {
0019 namespace grammar {
0020 
0021 namespace implementation_defined
0022 {
0023 template<class T, class = void>
0024 struct is_rule : std::false_type {};
0025 
0026 template<class T>
0027 struct is_rule<T, void_t<decltype(
0028     std::declval<system::result<typename T::value_type>&>() =
0029         std::declval<T const&>().parse(
0030             std::declval<char const*&>(),
0031             std::declval<char const*>())
0032     )>> : std::is_nothrow_copy_constructible<T>
0033 {
0034 };
0035 }
0036 
0037 /** Determine if T meets the requirements of @ref Rule
0038 
0039     This is an alias for `std::true_type` if
0040     `T` meets the requirements, otherwise it
0041     is an alias for `std::false_type`.
0042 
0043     @par Example
0044     @code
0045     struct U
0046     {
0047         struct value_type;
0048 
0049         auto
0050         parse(
0051             char const*& it,
0052             char const* end) const ->
0053                 system::result<value_type>
0054     };
0055 
0056     static_assert( is_rule<U>::value, "Requirements not met" );
0057     @endcode
0058 
0059     @see
0060         @ref parse.
0061 */
0062 template<class T>
0063 using is_rule = implementation_defined::is_rule<T>;
0064 
0065 #ifdef BOOST_URL_HAS_CONCEPTS
0066 /** Concept for a grammar Rule
0067 
0068     This concept is satisfied if `T` is a
0069     valid grammar Rule
0070 
0071     A `Rule` defines an algorithm used to match an input
0072     buffer of ASCII characters against a set of syntactical
0073     specifications.
0074 
0075     Each rule represents either a terminal symbol or a
0076     composition in the represented grammar.
0077 
0078     The library comes with a set of rules for productions
0079     typically found in RFC documents.
0080     Rules are not invoked directly; instead, rule variables are
0081     used with overloads of @ref parse which provide a convenient,
0082     uniform front end.
0083 
0084     @par Exemplar
0085 
0086     For best results, it is suggested that all constructors for
0087     rules be marked `constexpr`.
0088 
0089     @code
0090     struct Rule
0091     {
0092         struct value_type;
0093 
0094         constexpr Rule( Rule const& ) noexcept = default;
0095 
0096         auto parse( char const*& it, char const* end ) const -> result< value_type >;
0097     };
0098 
0099     // Declare a variable of type Rule for notational convenience
0100     constexpr Rule rule{};
0101     @endcode
0102 
0103     @par Model
0104 
0105     @li @ref dec_octet_rule
0106     @li @ref delim_rule
0107     @li @ref not_empty_rule
0108     @li @ref optional_rule
0109     @li @ref range_rule
0110     @li @ref token_rule
0111     @li @ref tuple_rule
0112     @li @ref unsigned_rule
0113     @li @ref variant_rule
0114 
0115     @see
0116         @ref parse,
0117         @ref is_rule.
0118  */
0119 template <class T>
0120 concept Rule =
0121     requires (T t, char const*& it, char const* end)
0122     {
0123         typename T::value_type;
0124         { t.parse(it, end) } -> std::same_as<system::result<typename T::value_type>>;
0125     };
0126 #endif
0127 
0128 
0129 } // grammar
0130 } // urls
0131 } // boost
0132 
0133 #endif