[#boost-urls-grammar-variant_rule] = xref:boost/urls/grammar/variant_rule.adoc[boost::urls::grammar::variant_rule] :relfileprefix: ../../../ :mrdocs: Match one of a set of rules == Synopsis Declared in `<https://www.github.com/boostorg/url/blob/develop/include/boost/url/grammar/variant_rule.hpp#L105[boost/url/grammar/variant_rule.hpp]>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< xref:boost/urls/grammar/Rule.adoc[Rule] R0, xref:boost/urls/grammar/Rule.adoc[Rule]... Rn> constexpr /* 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. == 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`]. [,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[] * https://datatracker.ietf.org/doc/html/rfc7230#section-5.3[] == Return Value The variant rule == Parameters [cols=2] |=== | 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_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-09.adoc[`parse`], xref:boost/urls/origin_form_rule.adoc[`origin_form_rule`], xref:boost/urls/url_view.adoc[`url_view`]. [.small]#Created with https://www.mrdocs.com[MrDocs]#