:relfileprefix: ../../../
[#boost-urls-grammar-variant_rule]

== xref:boost.adoc[pass:[boost]]::xref:boost/urls.adoc[pass:[urls]]::xref:boost/urls/grammar.adoc[pass:[grammar]]::variant_rule


Match one of a set of rules


=== Synopsis

Declared in header `<https://www.github.com/boostorg/url/blob/develop/include/boost/url/grammar/variant_rule.hpp#L157[boost/url/grammar/variant_rule.hpp,window=blank_]>`

[source,cpp,subs="verbatim,macros,-callouts"]
----
template<
    class R0,
    class... Rn>
constexpr
pass:q[_implementation-defined_]
variant_rule(
    R0 const& r0,
    Rn const&... rn) noexcept;
----

=== Description


Each specified rule is tried in sequence.
When the first match occurs, the result
is stored and returned in the variant. If
no match occurs, an error is returned.
[,cpp]
----
using value_type = variant< typename Rules::value_type... >;
----

=== Rules are used with the function

xref:boost/urls/grammar/parse-02.adoc[parse]
.
[,cpp]
----
// request-target = origin-form
//                / absolute-form
//                / authority-form
//                / asterisk-form

system::result< variant< url_view, url_view, authority_view, core::string_view > > rv = grammar::parse(
    "/index.html?width=full",
    variant_rule(
        origin_form_rule,
        absolute_uri_rule,
        authority_rule,
        delim_rule('*') ) );
----
[,cpp]
----
variant     = rule1 / rule2 / rule3...
----

* link:https://datatracker.ietf.org/doc/html/rfc5234#section-3.2[3.2.  Alternatives (rfc5234)]

* link:https://datatracker.ietf.org/doc/html/rfc7230#section-5.3[5.3.  Request Target (rfc7230)]








=== See Also


xref:boost/urls/absolute_uri_rule.adoc[absolute_uri_rule]
,
xref:boost/urls/authority_rule.adoc[authority_rule]
,
xref:boost/urls/grammar/delim_rule-0a.adoc[delim_rule]
,
xref:boost/urls/grammar/parse-02.adoc[parse]
,
xref:boost/urls/origin_form_rule.adoc[origin_form_rule]
,
xref:boost/urls/url_view.adoc[url_view]
.



