Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/url/grammar/impl/variant_rule.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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