From fc88bc06ad8d69d87f251218726970b404dd98a8 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Fri, 4 Jan 2013 00:58:17 +0000 Subject: [PATCH] [range] fixed #7843 (missing example in docs for 'tokenized' range adaptor) [SVN r82345] --- doc/html/index.html | 2 +- .../adaptors/reference/tokenized.html | 45 +++++++++++++ doc/reference/adaptors/examples/tokenized.cpp | 28 -------- doc/reference/adaptors/tokenized.qbk | 18 +++++ test/Jamfile.v2 | 4 +- test/adaptor_test/tokenized_example.cpp | 65 +++++++++++++++++++ 6 files changed, 131 insertions(+), 31 deletions(-) delete mode 100644 doc/reference/adaptors/examples/tokenized.cpp create mode 100644 test/adaptor_test/tokenized_example.cpp diff --git a/doc/html/index.html b/doc/html/index.html index b37d1e2..9f990d6 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -147,7 +147,7 @@

- +

Last revised: January 03, 2013 at 23:22:09 GMT

Last revised: January 04, 2013 at 00:56:46 GMT


diff --git a/doc/html/range/reference/adaptors/reference/tokenized.html b/doc/html/range/reference/adaptors/reference/tokenized.html index 1b9a97d..80396f0 100644 --- a/doc/html/range/reference/adaptors/reference/tokenized.html +++ b/doc/html/range/reference/adaptors/reference/tokenized.html @@ -26,6 +26,7 @@
tokenized
+
tokenized_example
@@ -134,6 +135,50 @@ Access Range +
+ +

+

+
#include <boost/range/adaptor/tokenized.hpp>
+#include <boost/range/algorithm/copy.hpp>
+#include <boost/assign.hpp>
+#include <algorithm>
+#include <iostream>
+#include <vector>
+
+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;
+}
+
+

+

+
+

+ This would produce the output: +

+
a
+b
+c
+d
+e
+f
+g
+hijklmnopqrstuvwxyz
+
+

+

diff --git a/doc/reference/adaptors/examples/tokenized.cpp b/doc/reference/adaptors/examples/tokenized.cpp deleted file mode 100644 index 273eaf1..0000000 --- a/doc/reference/adaptors/examples/tokenized.cpp +++ /dev/null @@ -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 -#include -#include -#include -#include -#include - -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; -} diff --git a/doc/reference/adaptors/tokenized.qbk b/doc/reference/adaptors/tokenized.qbk index 2127785..0a480d4 100644 --- a/doc/reference/adaptors/tokenized.qbk +++ b/doc/reference/adaptors/tokenized.qbk @@ -44,6 +44,24 @@ * [*Range Return Type:] `boost::tokenized_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] diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 4eb4506..d76c141 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -31,7 +31,6 @@ rule range-test ( name : includes * ) } test-suite range : - [ compile ../doc/reference/adaptors/examples/tokenized.cpp : : example_tokenized ] [ compile-fail compile_fail/iterator_range1.cpp ] [ range-test adaptor_test/adjacent_filtered ] [ range-test adaptor_test/copied ] @@ -47,6 +46,7 @@ test-suite range : [ range-test adaptor_test/strided2 ] [ range-test adaptor_test/tokenized ] [ range-test adaptor_test/transformed ] + [ range-test adaptor_test/type_erased ] [ range-test adaptor_test/uniqued ] [ range-test adaptor_test/adjacent_filtered_example ] [ range-test adaptor_test/copied_example ] @@ -61,7 +61,7 @@ test-suite range : [ range-test adaptor_test/sliced_example ] [ range-test adaptor_test/strided_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/uniqued_example ] [ range-test algorithm_test/adjacent_find ] diff --git a/test/adaptor_test/tokenized_example.cpp b/test/adaptor_test/tokenized_example.cpp new file mode 100644 index 0000000..243e47f --- /dev/null +++ b/test/adaptor_test/tokenized_example.cpp @@ -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 +#include +#include +#include +#include +#include + +//<- +#include +#include + +#include + +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(std::cout, "\n")); + +//= return 0; +//=} +//] + using namespace boost::assign; + + std::vector reference; + reference += "a","b","c","d","e","f","g","hijklmnopqrstuvwxyz"; + + std::vector 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; +}