[#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#Lundefined[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]&period;&period;&period; Rn&gt;
constexpr
&sol;&ast; implementation-defined &ast;&sol;
variant&lowbar;rule(
    R0 const& r0,
    Rn const&&period;&period;&period; 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-09.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

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

== Return Value

The variant rule

== Parameters

[cols="1,4"]
|===
|Name|Description

| *r0*
| The first rule to match
| *rn*
| A list of one or more rules to match
|===

== 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-0a.adoc[`delim&lowbar;rule`], xref:boost/urls/grammar/parse-09.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]#
