forked from boostorg/range
[range] fixed #7843 (missing example in docs for 'tokenized' range adaptor)
[SVN r82345]
This commit is contained in:
@ -147,7 +147,7 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||||
<td align="left"><p><small>Last revised: January 03, 2013 at 23:22:09 GMT</small></p></td>
|
<td align="left"><p><small>Last revised: January 04, 2013 at 00:56:46 GMT</small></p></td>
|
||||||
<td align="right"><div class="copyright-footer"></div></td>
|
<td align="right"><div class="copyright-footer"></div></td>
|
||||||
</tr></table>
|
</tr></table>
|
||||||
<hr>
|
<hr>
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
<div class="titlepage"><div><div><h5 class="title">
|
<div class="titlepage"><div><div><h5 class="title">
|
||||||
<a name="range.reference.adaptors.reference.tokenized"></a><a class="link" href="tokenized.html" title="tokenized">tokenized</a>
|
<a name="range.reference.adaptors.reference.tokenized"></a><a class="link" href="tokenized.html" title="tokenized">tokenized</a>
|
||||||
</h5></div></div></div>
|
</h5></div></div></div>
|
||||||
|
<div class="toc"><dl><dt><span class="section"><a href="tokenized.html#range.reference.adaptors.reference.tokenized.tokenized_example">tokenized_example</a></span></dt></dl></div>
|
||||||
<div class="informaltable"><table class="table">
|
<div class="informaltable"><table class="table">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col>
|
<col>
|
||||||
@ -134,6 +135,50 @@
|
|||||||
Access Range</a>
|
Access Range</a>
|
||||||
</li>
|
</li>
|
||||||
</ul></div>
|
</ul></div>
|
||||||
|
<div class="section range_reference_adaptors_reference_tokenized_tokenized_example">
|
||||||
|
<div class="titlepage"><div><div><h6 class="title">
|
||||||
|
<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>
|
||||||
|
</h6></div></div></div>
|
||||||
|
<p>
|
||||||
|
</p>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">algorithm</span><span class="special">></span>
|
||||||
|
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span>
|
||||||
|
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">vector</span><span class="special">></span>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
<span class="special">{</span>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">copy</span><span class="special">(</span>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
|
||||||
|
<span class="special">}</span>
|
||||||
|
</pre>
|
||||||
|
<p>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<p>
|
||||||
|
This would produce the output:
|
||||||
|
</p>
|
||||||
|
<pre class="programlisting"><span class="identifier">a</span>
|
||||||
|
<span class="identifier">b</span>
|
||||||
|
<span class="identifier">c</span>
|
||||||
|
<span class="identifier">d</span>
|
||||||
|
<span class="identifier">e</span>
|
||||||
|
<span class="identifier">f</span>
|
||||||
|
<span class="identifier">g</span>
|
||||||
|
<span class="identifier">hijklmnopqrstuvwxyz</span>
|
||||||
|
</pre>
|
||||||
|
<p>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||||
<td align="left"></td>
|
<td align="left"></td>
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
// Boost.Range library
|
|
||||||
//
|
|
||||||
// Copyright Thorsten Ottosen 2003-2004. Use, modification and
|
|
||||||
// distribution is subject to the Boost Software License, Version
|
|
||||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
//
|
|
||||||
// For more information, see http://www.boost.org/libs/range/
|
|
||||||
//
|
|
||||||
#include <boost/range/adaptor/tokenized.hpp>
|
|
||||||
#include <boost/range/algorithm_ext/push_back.hpp>
|
|
||||||
#include <boost/assert.hpp>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
int main(int argc, const char* argv[])
|
|
||||||
{
|
|
||||||
using namespace boost::adaptors;
|
|
||||||
|
|
||||||
std::string input = " a b c d e f g hijklmnopqrstuvwxyz";
|
|
||||||
std::vector< boost::sub_match< std::string::iterator > > result;
|
|
||||||
boost::push_back(result, input | tokenized(boost::regex("\\b")));
|
|
||||||
|
|
||||||
BOOST_ASSERT( boost::size(result) == 16u );
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -44,6 +44,24 @@
|
|||||||
* [*Range Return Type:] `boost::tokenized_range<typeof(rng)>`
|
* [*Range Return Type:] `boost::tokenized_range<typeof(rng)>`
|
||||||
* [*Returned Range Category:] __random_access_range__
|
* [*Returned Range Category:] __random_access_range__
|
||||||
|
|
||||||
|
[section:tokenized_example tokenized_example]
|
||||||
|
[import ../../../test/adaptor_test/tokenized_example.cpp]
|
||||||
|
[tokenized_example]
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
This would produce the output:
|
||||||
|
``
|
||||||
|
a
|
||||||
|
b
|
||||||
|
c
|
||||||
|
d
|
||||||
|
e
|
||||||
|
f
|
||||||
|
g
|
||||||
|
hijklmnopqrstuvwxyz
|
||||||
|
|
||||||
|
``
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@ rule range-test ( name : includes * )
|
|||||||
}
|
}
|
||||||
|
|
||||||
test-suite range :
|
test-suite range :
|
||||||
[ compile ../doc/reference/adaptors/examples/tokenized.cpp : : example_tokenized ]
|
|
||||||
[ compile-fail compile_fail/iterator_range1.cpp ]
|
[ compile-fail compile_fail/iterator_range1.cpp ]
|
||||||
[ range-test adaptor_test/adjacent_filtered ]
|
[ range-test adaptor_test/adjacent_filtered ]
|
||||||
[ range-test adaptor_test/copied ]
|
[ range-test adaptor_test/copied ]
|
||||||
@ -47,6 +46,7 @@ test-suite range :
|
|||||||
[ range-test adaptor_test/strided2 ]
|
[ range-test adaptor_test/strided2 ]
|
||||||
[ range-test adaptor_test/tokenized ]
|
[ range-test adaptor_test/tokenized ]
|
||||||
[ range-test adaptor_test/transformed ]
|
[ range-test adaptor_test/transformed ]
|
||||||
|
[ range-test adaptor_test/type_erased ]
|
||||||
[ range-test adaptor_test/uniqued ]
|
[ range-test adaptor_test/uniqued ]
|
||||||
[ range-test adaptor_test/adjacent_filtered_example ]
|
[ range-test adaptor_test/adjacent_filtered_example ]
|
||||||
[ range-test adaptor_test/copied_example ]
|
[ range-test adaptor_test/copied_example ]
|
||||||
@ -61,7 +61,7 @@ test-suite range :
|
|||||||
[ range-test adaptor_test/sliced_example ]
|
[ range-test adaptor_test/sliced_example ]
|
||||||
[ range-test adaptor_test/strided_example ]
|
[ range-test adaptor_test/strided_example ]
|
||||||
[ range-test adaptor_test/transformed_example ]
|
[ range-test adaptor_test/transformed_example ]
|
||||||
[ range-test adaptor_test/type_erased ]
|
[ range-test adaptor_test/tokenized_example ]
|
||||||
[ range-test adaptor_test/type_erased_example ]
|
[ range-test adaptor_test/type_erased_example ]
|
||||||
[ range-test adaptor_test/uniqued_example ]
|
[ range-test adaptor_test/uniqued_example ]
|
||||||
[ range-test algorithm_test/adjacent_find ]
|
[ range-test algorithm_test/adjacent_find ]
|
||||||
|
65
test/adaptor_test/tokenized_example.cpp
Normal file
65
test/adaptor_test/tokenized_example.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
// Boost.Range library
|
||||||
|
//
|
||||||
|
// Copyright Neil Groves 2009. Use, modification and
|
||||||
|
// distribution is subject to the Boost Software License, Version
|
||||||
|
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// For more information, see http://www.boost.org/libs/range/
|
||||||
|
//
|
||||||
|
//[tokenized_example
|
||||||
|
#include <boost/range/adaptor/tokenized.hpp>
|
||||||
|
#include <boost/range/algorithm/copy.hpp>
|
||||||
|
#include <boost/assign.hpp>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
//<-
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
#include <boost/range/algorithm_ext/push_back.hpp>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
void tokenized_example_test()
|
||||||
|
//->
|
||||||
|
//=int main(int argc, const char* argv[])
|
||||||
|
{
|
||||||
|
using namespace boost::adaptors;
|
||||||
|
|
||||||
|
typedef boost::sub_match< std::string::iterator > match_type;
|
||||||
|
|
||||||
|
std::string input = " a b c d e f g hijklmnopqrstuvwxyz";
|
||||||
|
boost::copy(
|
||||||
|
input | tokenized(boost::regex("\\w+")),
|
||||||
|
std::ostream_iterator<match_type>(std::cout, "\n"));
|
||||||
|
|
||||||
|
//= return 0;
|
||||||
|
//=}
|
||||||
|
//]
|
||||||
|
using namespace boost::assign;
|
||||||
|
|
||||||
|
std::vector<std::string> reference;
|
||||||
|
reference += "a","b","c","d","e","f","g","hijklmnopqrstuvwxyz";
|
||||||
|
|
||||||
|
std::vector<match_type> test;
|
||||||
|
boost::push_back(test, input | tokenized(boost::regex("\\w+")));
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||||
|
test.begin(), test.end() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::unit_test::test_suite*
|
||||||
|
init_unit_test_suite(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
boost::unit_test::test_suite* test
|
||||||
|
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.tokenized_example" );
|
||||||
|
|
||||||
|
test->add( BOOST_TEST_CASE( &tokenized_example_test ) );
|
||||||
|
|
||||||
|
return test;
|
||||||
|
}
|
Reference in New Issue
Block a user