[#boost-urls-grammar-variant_rule]
= xref:boost.adoc[boost]::xref:boost/urls.adoc[urls]::xref:boost/urls/grammar.adoc[grammar]::variant&lowbar;rule
:relfileprefix: ../../../
:mrdocs:


Match one of a set of rules

== Synopsis


Declared in `&lt;https://www.github.com/boostorg/url/blob/develop/include/boost/url/grammar/variant_rule.hpp#L101[boost&sol;url&sol;grammar&sol;variant&lowbar;rule&period;hpp]&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    xref:boost/urls/grammar/Rule.adoc[Rule] R0,
    xref:boost/urls/grammar/Rule.adoc[Rule]... Rn&gt;
constexpr
&sol;&ast; implementation-defined &ast;&sol;::xref:boost/urls/grammar/implementation_defined/variant_rule_t.adoc[variant&lowbar;rule&lowbar;t]&lt;R0, Rn...&gt;
variant&lowbar;rule(
    R0 const& r0,
    Rn const&... rn) noexcept;
----

== Description


Each specified rule is tried in sequence&period;    When the first match occurs, the result    is stored and returned in the variant&period; If    no match occurs, an error is returned&period;


=== Value Type

[,cpp]
----
using value_type = variant< typename Rules::value_type... >;
----

=== Example

Rules are used with the function xref:boost/urls/grammar/parse-02.adoc[parse]&period;

[,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('*') ) );
----

=== BNF

[,cpp]
----
variant     = rule1 / rule2 / rule3...
----

=== Specification

* link:https://datatracker.ietf.org/doc/html/rfc5234#section-3.2[3&period;2&period;  Alternatives (rfc5234)]
    
* link:https://datatracker.ietf.org/doc/html/rfc7230#section-5.3[5&period;3&period;  Request Target (rfc7230)]



== See Also


xref:boost/urls/absolute_uri_rule.adoc[absolute&lowbar;uri&lowbar;rule],        xref:boost/urls/authority_rule.adoc[authority&lowbar;rule],        xref:boost/urls/grammar/delim_rule-01.adoc[delim&lowbar;rule],        xref:boost/urls/grammar/parse-02.adoc[parse],        xref:boost/urls/origin_form_rule.adoc[origin&lowbar;form&lowbar;rule],        xref:boost/urls/url_view.adoc[url&lowbar;view]&period;






[.small]#Created with https://www.mrdocs.com[MrDocs]#
