Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:27

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot 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_IMPL_VARIANT_RULE_HPP
0011 #define BOOST_URL_GRAMMAR_IMPL_VARIANT_RULE_HPP
0012 
0013 #include <boost/url/grammar/error.hpp>
0014 #include <boost/url/grammar/parse.hpp>
0015 #include <cstdint>
0016 #include <type_traits>
0017 
0018 namespace boost {
0019 namespace urls {
0020 namespace grammar {
0021 
0022 namespace detail {
0023 
0024 // must come first
0025 template<
0026     class R0,
0027     class... Rn,
0028     std::size_t I>
0029 auto
0030 parse_variant(
0031     char const*&,
0032     char const*,
0033     detail::tuple<
0034         R0, Rn...> const&,
0035     std::integral_constant<
0036         std::size_t, I> const&,
0037     std::false_type const&) ->
0038         system::result<variant<
0039             typename R0::value_type,
0040             typename Rn::value_type...>>
0041 {
0042     // no match
0043     BOOST_URL_RETURN_EC(
0044         error::mismatch);
0045 }
0046 
0047 template<
0048     class R0,
0049     class... Rn,
0050     std::size_t I>
0051 auto
0052 parse_variant(
0053     char const*& it,
0054     char const* const end,
0055     detail::tuple<
0056         R0, Rn...> const& rn,
0057     std::integral_constant<
0058         std::size_t, I> const&,
0059     std::true_type const&) ->
0060         system::result<variant<
0061             typename R0::value_type,
0062             typename Rn::value_type...>>
0063 {
0064     auto const it0 = it;
0065     auto rv = parse(
0066         it, end, get<I>(rn));
0067     if( rv )
0068         return variant<
0069             typename R0::value_type,
0070             typename Rn::value_type...>{
0071                 variant2::in_place_index_t<I>{}, *rv};
0072     it = it0;
0073     return parse_variant(
0074         it, end, rn,
0075         std::integral_constant<
0076             std::size_t, I+1>{},
0077         std::integral_constant<bool,
0078             ((I + 1) < (1 +
0079                 sizeof...(Rn)))>{});
0080 }
0081 
0082 } // detail
0083 
0084 template<class R0, class... Rn>
0085 auto
0086 variant_rule_t<R0, Rn...>::
0087 parse(
0088     char const*& it,
0089     char const* end) const ->
0090         system::result<value_type>
0091 {
0092     return detail::parse_variant(
0093         it, end, rn_,
0094         std::integral_constant<
0095             std::size_t, 0>{},
0096         std::true_type{});
0097 }
0098 
0099 //------------------------------------------------
0100 
0101 template<class R0, class... Rn>
0102 auto
0103 constexpr
0104 variant_rule(
0105     R0 const& r0,
0106     Rn const&... rn) noexcept ->
0107         variant_rule_t<R0, Rn...>
0108 {
0109     return { r0, rn... };
0110 }
0111 
0112 } // grammar
0113 } // urls
0114 } // boost
0115 
0116 #endif