1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Permutation Parser (a ^ b)</title> 5<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../../../index.html" title="Spirit 2.5.8"> 8<link rel="up" href="../operator.html" title="Parser Operators"> 9<link rel="prev" href="optional.html" title="Optional Parser (-a)"> 10<link rel="next" href="plus.html" title="Plus Parser (+a)"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="optional.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../operator.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="plus.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h5 class="title"> 27<a name="spirit.qi.reference.operator.permutation"></a><a class="link" href="permutation.html" title="Permutation Parser (a ^ b)">Permutation 28 Parser (<code class="computeroutput"><span class="identifier">a</span> <span class="special">^</span> 29 <span class="identifier">b</span></code>)</a> 30</h5></div></div></div> 31<h6> 32<a name="spirit.qi.reference.operator.permutation.h0"></a> 33 <span class="phrase"><a name="spirit.qi.reference.operator.permutation.description"></a></span><a class="link" href="permutation.html#spirit.qi.reference.operator.permutation.description">Description</a> 34 </h6> 35<p> 36 The permutation operator, <code class="computeroutput"><span class="identifier">a</span> 37 <span class="special">^</span> <span class="identifier">b</span></code>, 38 matches one or more operands (<code class="computeroutput"><span class="identifier">a</span></code>, 39 <code class="computeroutput"><span class="identifier">b</span></code>, ... etc.) in any order: 40 </p> 41<pre class="programlisting"><span class="identifier">a</span> <span class="special">^</span> <span class="identifier">b</span> <span class="special">^</span> <span class="special">...</span> 42</pre> 43<p> 44 The operands are the elements in the permutation set. Each element in 45 the permutation set may occur at most once, but not all elements of the 46 given set need to be present. Note that by this definition, the permutation 47 operator is not limited to strict permutations. 48 </p> 49<p> 50 For example: 51 </p> 52<pre class="programlisting"><span class="identifier">char_</span><span class="special">(</span><span class="char">'a'</span><span class="special">)</span> <span class="special">^</span> <span class="char">'b'</span> <span class="special">^</span> <span class="char">'c'</span> 53</pre> 54<p> 55 matches: 56 </p> 57<pre class="programlisting"><span class="string">"a"</span><span class="special">,</span> <span class="string">"ab"</span><span class="special">,</span> <span class="string">"abc"</span><span class="special">,</span> <span class="string">"cba"</span><span class="special">,</span> <span class="string">"bca"</span> <span class="special">...</span> <span class="identifier">etc</span><span class="special">.</span> 58</pre> 59<h6> 60<a name="spirit.qi.reference.operator.permutation.h1"></a> 61 <span class="phrase"><a name="spirit.qi.reference.operator.permutation.header"></a></span><a class="link" href="permutation.html#spirit.qi.reference.operator.permutation.header">Header</a> 62 </h6> 63<pre class="programlisting"><span class="comment">// forwards to <boost/spirit/home/qi/operator/permutation.hpp></span> 64<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">qi_permutation</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 65</pre> 66<p> 67 Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>. 68 </p> 69<h6> 70<a name="spirit.qi.reference.operator.permutation.h2"></a> 71 <span class="phrase"><a name="spirit.qi.reference.operator.permutation.model_of"></a></span><a class="link" href="permutation.html#spirit.qi.reference.operator.permutation.model_of">Model of</a> 72 </h6> 73<div class="blockquote"><blockquote class="blockquote"><p> 74 <a class="link" href="../parser_concepts/naryparser.html" title="NaryParser"><code class="computeroutput"><span class="identifier">NaryParser</span></code></a> 75 </p></blockquote></div> 76<div class="variablelist"> 77<p class="title"><b>Notation</b></p> 78<dl class="variablelist"> 79<dt><span class="term"><code class="computeroutput"><span class="identifier">a</span></code>, <code class="computeroutput"><span class="identifier">b</span></code></span></dt> 80<dd><p> 81 A <a class="link" href="../parser_concepts/parser.html" title="Parser"><code class="computeroutput"><span class="identifier">Parser</span></code></a> 82 </p></dd> 83</dl> 84</div> 85<h6> 86<a name="spirit.qi.reference.operator.permutation.h3"></a> 87 <span class="phrase"><a name="spirit.qi.reference.operator.permutation.expression_semantics"></a></span><a class="link" href="permutation.html#spirit.qi.reference.operator.permutation.expression_semantics">Expression 88 Semantics</a> 89 </h6> 90<p> 91 Semantics of an expression is defined only where it differs from, or 92 is not defined in <a class="link" href="../parser_concepts/naryparser.html" title="NaryParser"><code class="computeroutput"><span class="identifier">NaryParser</span></code></a>. 93 </p> 94<div class="informaltable"><table class="table"> 95<colgroup> 96<col> 97<col> 98</colgroup> 99<thead><tr> 100<th> 101 <p> 102 Expression 103 </p> 104 </th> 105<th> 106 <p> 107 Semantics 108 </p> 109 </th> 110</tr></thead> 111<tbody><tr> 112<td> 113 <p> 114 <code class="computeroutput"><span class="identifier">a</span> <span class="special">^</span> 115 <span class="identifier">b</span></code> 116 </p> 117 </td> 118<td> 119 <p> 120 Match <code class="computeroutput"><span class="identifier">a</span></code> or 121 <code class="computeroutput"><span class="identifier">b</span></code> in any order. 122 Each operand may match zero or one time as long as at least 123 one operand matches. 124 </p> 125 </td> 126</tr></tbody> 127</table></div> 128<h6> 129<a name="spirit.qi.reference.operator.permutation.h4"></a> 130 <span class="phrase"><a name="spirit.qi.reference.operator.permutation.attributes"></a></span><a class="link" href="permutation.html#spirit.qi.reference.operator.permutation.attributes">Attributes</a> 131 </h6> 132<p> 133 See <a class="link" href="../../quick_reference/compound_attribute_rules.html#spirit.qi.quick_reference.compound_attribute_rules.notation">Compound 134 Attribute Notation</a>. 135 </p> 136<div class="informaltable"><table class="table"> 137<colgroup> 138<col> 139<col> 140</colgroup> 141<thead><tr> 142<th> 143 <p> 144 Expression 145 </p> 146 </th> 147<th> 148 <p> 149 Attribute 150 </p> 151 </th> 152</tr></thead> 153<tbody><tr> 154<td> 155 <p> 156 <code class="computeroutput"><span class="identifier">a</span> <span class="special">^</span> 157 <span class="identifier">b</span></code> 158 </p> 159 </td> 160<td> 161 <p> 162</p> 163<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">B</span> <span class="special">--></span> <span class="special">(</span><span class="identifier">a</span> <span class="special">^</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">tuple</span><span class="special"><</span><span class="identifier">optional</span><span class="special"><</span><span class="identifier">A</span><span class="special">>,</span> <span class="identifier">optional</span><span class="special"><</span><span class="identifier">B</span><span class="special">></span> <span class="special">></span> 164<span class="identifier">a</span><span class="special">:</span> <span class="identifier">A</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--></span> <span class="special">(</span><span class="identifier">a</span> <span class="special">^</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">optional</span><span class="special"><</span><span class="identifier">A</span><span class="special">></span> 165<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">B</span> <span class="special">--></span> <span class="special">(</span><span class="identifier">a</span> <span class="special">^</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">optional</span><span class="special"><</span><span class="identifier">B</span><span class="special">></span> 166<span class="identifier">a</span><span class="special">:</span> <span class="identifier">Unused</span><span class="special">,</span> <span class="identifier">b</span><span class="special">:</span> <span class="identifier">Unused</span> <span class="special">--></span> <span class="special">(</span><span class="identifier">a</span> <span class="special">^</span> <span class="identifier">b</span><span class="special">):</span> <span class="identifier">Unused</span></pre> 167<p> 168 </p> 169 </td> 170</tr></tbody> 171</table></div> 172<h6> 173<a name="spirit.qi.reference.operator.permutation.h5"></a> 174 <span class="phrase"><a name="spirit.qi.reference.operator.permutation.complexity"></a></span><a class="link" href="permutation.html#spirit.qi.reference.operator.permutation.complexity">Complexity</a> 175 </h6> 176<div class="blockquote"><blockquote class="blockquote"><p> 177 The overall complexity of the permutation parser is defined by the 178 sum of the complexities of its elements, s, multiplied by log s. The 179 complexity of the permutation parser itself is O(N log N), where N 180 is the number of elements. 181 </p></blockquote></div> 182<h6> 183<a name="spirit.qi.reference.operator.permutation.h6"></a> 184 <span class="phrase"><a name="spirit.qi.reference.operator.permutation.example"></a></span><a class="link" href="permutation.html#spirit.qi.reference.operator.permutation.example">Example</a> 185 </h6> 186<div class="note"><table border="0" summary="Note"> 187<tr> 188<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td> 189<th align="left">Note</th> 190</tr> 191<tr><td align="left" valign="top"><p> 192 The test harness for the example(s) below is presented in the <a class="link" href="../basics.html#spirit.qi.reference.basics.examples">Basics Examples</a> 193 section. 194 </p></td></tr> 195</table></div> 196<p> 197 Some using declarations: 198 </p> 199<p> 200</p> 201<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">ascii</span><span class="special">::</span><span class="identifier">char_</span><span class="special">;</span> 202</pre> 203<p> 204 </p> 205<p> 206 Parse a string containing DNA codes (ACTG) 207 </p> 208<p> 209</p> 210<pre class="programlisting"><span class="identifier">test_parser</span><span class="special">(</span><span class="string">"ACTGGCTAGACT"</span><span class="special">,</span> <span class="special">*(</span><span class="identifier">char_</span><span class="special">(</span><span class="char">'A'</span><span class="special">)</span> <span class="special">^</span> <span class="char">'C'</span> <span class="special">^</span> <span class="char">'T'</span> <span class="special">^</span> <span class="char">'G'</span><span class="special">));</span> 211</pre> 212<p> 213 </p> 214</div> 215<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 216<td align="left"></td> 217<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p> 218 Distributed under the Boost Software License, Version 1.0. (See accompanying 219 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 220 </p> 221</div></td> 222</tr></table> 223<hr> 224<div class="spirit-nav"> 225<a accesskey="p" href="optional.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../operator.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="plus.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 226</div> 227</body> 228</html> 229