Skip to content
Browse files

add as_container document.

  • Loading branch information...
1 parent 605e5a4 commit 6b3747750df302148feb6deb90c3c21afb900f16 @faithandbrave committed Jan 1, 2013
View
0 boost/range/experimental/as_container.hpp → boost/range/as_container.hpp
File renamed without changes.
View
3 libs/range/doc/reference/range_utility.qbk
@@ -5,12 +5,13 @@
/]
[section Algorithm Extension]
+[include range_utility/as_container.qbk]
[include range_utility/directory_range.qbk]
[include range_utility/iteration.qbk]
[include range_utility/recursive_directory_range.qbk]
+[include range_utility/regular.qbk]
[include range_utility/single.qbk]
[include range_utility/split_at.qbk]
-[include range_utility/regular.qbk]
[endsect]
View
63 libs/range/doc/reference/range_utility/as_container.qbk
@@ -0,0 +1,63 @@
+[/
+ Copyright 2011-2013 Akira Takahashi
+ Distributed under 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)
+/]
+[section:as_container as_container]
+
+`as_container` automagically calls the range-constructor of the target range without specifying the type.
+
+[table
+ [[Syntax] [Code]]
+ [[Pipe] [`container c = rng | boost::as_container`]]
+ [[Function] [`container c = boost::as_container(rng)`]]
+]
+
+'container c = rng | boost::as_container;'
+This experession's semantics is follow:
+'container c(boost::begin(rng), boost::end(rng));'
+
+[heading Namespace]
+
+`boost`.
+
+[heading Header]
+``
+<boost/range/as_container.hpp>
+``
+
+[heading Example]
+
+``
+#include <iostream>
+#include <vector>
+#include <boost/assign/list_of.hpp>
+#include <boost/range/algorithm/for_each.hpp>
+#include <boost/range/adaptor/filtered.hpp>
+#include <boost/range/adaptor/transformed.hpp>
+#include <boost/range/as_container.hpp>
+
+bool is_even(int x) { return x % 2 == 0; }
+int add(int x) { return x + 1; }
+void disp(int x) { std::cout << x << std::endl; }
+
+int main()
+{
+ const std::vector<int> v = boost::assign::list_of(1)(2)(3)(4)(5);
+
+ const std::vector<int> v2 = v | boost::adaptors::filtered(is_even)
+ | boost::adaptors::transformed(add)
+ | boost::as_container;
+
+ boost::for_each(v2, disp);
+}
+``
+
+This would produce the output:
+``
+3
+5
+
+``
+
+[endsect]
View
2 libs/range/test/as_container.cpp
@@ -15,7 +15,7 @@
#include <boost/assign/list_of.hpp>
#include <boost/range/adaptor/filtered.hpp>
-#include <boost/range/experimental/as_container.hpp>
+#include <boost/range/as_container.hpp>
bool is_odd(int x) { return x % 2 == 0; }

0 comments on commit 6b37477

Please sign in to comment.
Something went wrong with that request. Please try again.