1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>tokenized</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="Chapter 1. Range 2.0"> 8<link rel="up" href="../reference.html" title="Reference"> 9<link rel="prev" href="type_erased.html" title="type_erased"> 10<link rel="next" href="transformed.html" title="transformed"> 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="type_erased.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.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="transformed.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="range.reference.adaptors.reference.tokenized"></a><a class="link" href="tokenized.html" title="tokenized">tokenized</a> 28</h5></div></div></div> 29<div class="toc"><dl class="toc"><dt><span class="section"><a href="tokenized.html#range.reference.adaptors.reference.tokenized.tokenized_example">tokenized_example</a></span></dt></dl></div> 30<div class="informaltable"><table class="table"> 31<colgroup> 32<col> 33<col> 34</colgroup> 35<thead><tr> 36<th> 37 <p> 38 Syntax 39 </p> 40 </th> 41<th> 42 <p> 43 Code 44 </p> 45 </th> 46</tr></thead> 47<tbody> 48<tr> 49<td> 50 <p> 51 Pipe 52 </p> 53 </td> 54<td> 55 <p> 56</p> 57<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">rng</span> <span class="special">|</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">adaptors</span><span class="special">::</span><span class="identifier">tokenized</span><span class="special">(</span><span class="identifier">regex</span><span class="special">)</span> 58<span class="identifier">rng</span> <span class="special">|</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">adaptors</span><span class="special">::</span><span class="identifier">tokenized</span><span class="special">(</span><span class="identifier">regex</span><span class="special">,</span> <span class="identifier">i</span><span class="special">)</span> 59<span class="identifier">rng</span> <span class="special">|</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">adaptors</span><span class="special">::</span><span class="identifier">tokenized</span><span class="special">(</span><span class="identifier">regex</span><span class="special">,</span> <span class="identifier">rndRng</span><span class="special">)</span> 60<span class="identifier">rng</span> <span class="special">|</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">adaptors</span><span class="special">::</span><span class="identifier">tokenized</span><span class="special">(</span><span class="identifier">regex</span><span class="special">,</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">flags</span><span class="special">)</span> 61<span class="identifier">rng</span> <span class="special">|</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">adaptors</span><span class="special">::</span><span class="identifier">tokenized</span><span class="special">(</span><span class="identifier">regex</span><span class="special">,</span> <span class="identifier">rndRng</span><span class="special">,</span> <span class="identifier">flags</span><span class="special">)</span> 62</pre> 63<p> 64 </p> 65 </td> 66</tr> 67<tr> 68<td> 69 <p> 70 Function 71 </p> 72 </td> 73<td> 74 <p> 75</p> 76<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">adaptors</span><span class="special">::</span><span class="identifier">tokenize</span><span class="special">(</span><span class="identifier">rng</span><span class="special">,</span> <span class="identifier">regex</span><span class="special">)</span> 77<span class="identifier">boost</span><span class="special">::</span><span class="identifier">adaptors</span><span class="special">::</span><span class="identifier">tokenize</span><span class="special">(</span><span class="identifier">rng</span><span class="special">,</span> <span class="identifier">regex</span><span class="special">,</span> <span class="identifier">i</span><span class="special">)</span> 78<span class="identifier">boost</span><span class="special">::</span><span class="identifier">adaptors</span><span class="special">::</span><span class="identifier">tokenize</span><span class="special">(</span><span class="identifier">rng</span><span class="special">,</span> <span class="identifier">regex</span><span class="special">,</span> <span class="identifier">rndRng</span><span class="special">)</span> 79<span class="identifier">boost</span><span class="special">::</span><span class="identifier">adaptors</span><span class="special">::</span><span class="identifier">tokenize</span><span class="special">(</span><span class="identifier">rng</span><span class="special">,</span> <span class="identifier">regex</span><span class="special">,</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">flags</span><span class="special">)</span> 80<span class="identifier">boost</span><span class="special">::</span><span class="identifier">adaptors</span><span class="special">::</span><span class="identifier">tokenize</span><span class="special">(</span><span class="identifier">rng</span><span class="special">,</span> <span class="identifier">regex</span><span class="special">,</span> <span class="identifier">rndRng</span><span class="special">,</span> <span class="identifier">flags</span><span class="special">)</span> 81</pre> 82<p> 83 </p> 84 </td> 85</tr> 86</tbody> 87</table></div> 88<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 89<li class="listitem"> 90 <span class="bold"><strong>Precondition:</strong></span> 91 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "> 92<li class="listitem"> 93 Let <code class="computeroutput"><span class="identifier">T</span></code> denote 94 <code class="computeroutput"><span class="keyword">typename</span> <span class="identifier">range_value</span><span class="special"><</span><span class="keyword">decltype</span><span class="special">(</span><span class="identifier">rng</span><span class="special">)>::</span><span class="identifier">type</span></code>, 95 then <code class="computeroutput"><span class="identifier">regex</span></code> 96 has the type <code class="computeroutput"><span class="identifier">basic_regex</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> or is implicitly convertible 97 to one of these types. 98 </li> 99<li class="listitem"> 100 <code class="computeroutput"><span class="identifier">i</span></code> has the type 101 <code class="computeroutput"><span class="keyword">int</span></code>. 102 </li> 103<li class="listitem"> 104 the <code class="computeroutput"><span class="identifier">value_type</span></code> 105 of <code class="computeroutput"><span class="identifier">rndRng</span></code> is 106 <code class="computeroutput"><span class="keyword">int</span></code>. 107 </li> 108<li class="listitem"> 109 <code class="computeroutput"><span class="identifier">flags</span></code> has the 110 type <code class="computeroutput"><span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">syntax_option_type</span></code>. 111 </li> 112</ul></div> 113 </li> 114<li class="listitem"> 115 <span class="bold"><strong>Returns:</strong></span> A range whose iterators 116 behave as if they were the original iterators wrapped in <code class="computeroutput"><span class="identifier">regex_token_iterator</span></code>. The first 117 iterator in the range would be constructed by forwarding all the 118 arguments of <code class="computeroutput"><span class="identifier">tokenized</span><span class="special">()</span></code> to the <code class="computeroutput"><span class="identifier">regex_token_iterator</span></code> 119 constructor. 120 </li> 121<li class="listitem"> 122 <span class="bold"><strong>Throws:</strong></span> Whatever constructing and 123 copying equivalent <code class="computeroutput"><span class="identifier">regex_token_iterator</span></code>s 124 might throw. 125 </li> 126<li class="listitem"> 127 <span class="bold"><strong>Range Category:</strong></span> <a class="link" href="../../../concepts/random_access_range.html" title="Random Access Range">Random 128 Access Range</a> 129 </li> 130<li class="listitem"> 131 <span class="bold"><strong>Range Return Type:</strong></span> <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tokenized_range</span><span class="special"><</span><span class="keyword">decltype</span><span class="special">(</span><span class="identifier">rng</span><span class="special">)></span></code> 132 </li> 133<li class="listitem"> 134 <span class="bold"><strong>Returned Range Category:</strong></span> <a class="link" href="../../../concepts/random_access_range.html" title="Random Access Range">Random 135 Access Range</a> 136 </li> 137</ul></div> 138<div class="section"> 139<div class="titlepage"><div><div><h6 class="title"> 140<a name="range.reference.adaptors.reference.tokenized.tokenized_example"></a><a class="link" href="tokenized.html#range.reference.adaptors.reference.tokenized.tokenized_example" title="tokenized_example">tokenized_example</a> 141</h6></div></div></div> 142<p> 143</p> 144<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">range</span><span class="special">/</span><span class="identifier">adaptor</span><span class="special">/</span><span class="identifier">tokenized</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 145<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">range</span><span class="special">/</span><span class="identifier">algorithm</span><span class="special">/</span><span class="identifier">copy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 146<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">assign</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 147<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iterator</span><span class="special">></span> 148<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span> 149<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">vector</span><span class="special">></span> 150 151<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">argc</span><span class="special">,</span> <span class="keyword">const</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">argv</span><span class="special">[])</span> 152<span class="special">{</span> 153 <span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">adaptors</span><span class="special">;</span> 154 155 <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">sub_match</span><span class="special"><</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">::</span><span class="identifier">iterator</span> <span class="special">></span> <span class="identifier">match_type</span><span class="special">;</span> 156 157 <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">input</span> <span class="special">=</span> <span class="string">" a b c d e f g hijklmnopqrstuvwxyz"</span><span class="special">;</span> 158 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">copy</span><span class="special">(</span> 159 <span class="identifier">input</span> <span class="special">|</span> <span class="identifier">tokenized</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">regex</span><span class="special">(</span><span class="string">"\\w+"</span><span class="special">)),</span> 160 <span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream_iterator</span><span class="special"><</span><span class="identifier">match_type</span><span class="special">>(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span><span class="special">,</span> <span class="string">"\n"</span><span class="special">));</span> 161 162 <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span> 163<span class="special">}</span> 164</pre> 165<p> 166 </p> 167</div> 168<p> 169 This would produce the output: 170</p> 171<pre class="programlisting"><span class="identifier">a</span> 172<span class="identifier">b</span> 173<span class="identifier">c</span> 174<span class="identifier">d</span> 175<span class="identifier">e</span> 176<span class="identifier">f</span> 177<span class="identifier">g</span> 178<span class="identifier">hijklmnopqrstuvwxyz</span> 179</pre> 180<p> 181 </p> 182</div> 183<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 184<td align="left"></td> 185<td align="right"><div class="copyright-footer">Copyright © 2003-2010 Thorsten Ottosen, 186 Neil Groves<p> 187 Distributed under the Boost Software License, Version 1.0. (See accompanying 188 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>) 189 </p> 190</div></td> 191</tr></table> 192<hr> 193<div class="spirit-nav"> 194<a accesskey="p" href="type_erased.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.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="transformed.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 195</div> 196</body> 197</html> 198