mirror of
https://github.com/boostorg/range.git
synced 2025-07-29 20:37:25 +02:00
Boost.RangeEx merged into Boost.Range
[SVN r60897]
This commit is contained in:
101
doc/reference/adaptors/adjacent_filtered.html
Executable file
101
doc/reference/adaptors/adjacent_filtered.html
Executable file
@ -0,0 +1,101 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Boost.Range Range Adaptors </title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<table border="0" >
|
||||
<tr>
|
||||
<td ><img src="../../../boost.png" border="0" /></td>
|
||||
<td ><h1 align="center">Boost.Range </h1></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2> Range Adaptors </h2>
|
||||
|
||||
<hr />
|
||||
<a name="adjacent_filtered"></a>
|
||||
<h4><code>adjacent_filtered</code></h4>
|
||||
<blockquote>
|
||||
<pre> rng | boost::adaptors::adjacent_filtered( bi_pred )
|
||||
</pre>
|
||||
<pre> boost::make_adjacent_filtered_range( rng, bi_pred )
|
||||
</pre>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Precondition:</b>
|
||||
The value-type of the range is convertible to both argument types
|
||||
of <code>bi_pred</code>.
|
||||
</li>
|
||||
<li>
|
||||
<b>Postcondition:</b>
|
||||
For all adjacent elements <code>[x,y]</code> in the returned range,
|
||||
<code>bi_pred(x,y)</code> is <code>true</code>.
|
||||
</li>
|
||||
<li>
|
||||
<b>Throws:</b>
|
||||
Whatever the copy-constructor of bi_pred might throw.
|
||||
</li>
|
||||
<li>
|
||||
<b>Range Category:</b>
|
||||
SinglePassRange
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<hr />
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
<span class="keyword">#include</span> <boost/range/adaptor/adjacent_filtered.hpp>
|
||||
<span class="keyword">#include</span> <boost/range/algorithm/copy.hpp>
|
||||
<span class="keyword">#include</span> <boost/assign.hpp>
|
||||
<span class="keyword">#include</span> <algorithm>
|
||||
<span class="keyword">#include</span> <functional>
|
||||
<span class="keyword">#include</span> <iostream>
|
||||
<span class="keyword">#include</span> <vector>
|
||||
|
||||
<span class="keyword">int</span> main(<span class="keyword">int</span> argc, <span class="keyword">const char</span>* argv[])
|
||||
{
|
||||
<span class="keyword">using namespace</span> boost::assign;
|
||||
<span class="keyword">using namespace</span> boost::adaptors;
|
||||
|
||||
std::vector<<span class="keyword">int</span>> input;
|
||||
input += 1,1,2,2,2,3,4,5,6;
|
||||
|
||||
boost::copy(
|
||||
input | adjacent_filtered(std::not_equal_to<<span class="keyword">int</span>>()),
|
||||
std::ostream_iterator<<span class="keyword">int</span>>(std::cout, ","));
|
||||
|
||||
<span class="keyword">return</span> 0;
|
||||
}
|
||||
</pre>
|
||||
<p>
|
||||
This would produce the output:<br />
|
||||
<code>1,2,3,4,5,6</code><br />
|
||||
</p>
|
||||
<hr />
|
||||
<p>
|
||||
(C) Copyright Neil Groves 2009
|
||||
(C) Copyright Thorsten Ottosen 2003-2004
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
</body>
|
||||
</html>
|
||||
|
47
doc/reference/adaptors/adjacent_filtered.qbk
Normal file
47
doc/reference/adaptors/adjacent_filtered.qbk
Normal file
@ -0,0 +1,47 @@
|
||||
[section:adjacent_filtered adjacent_filtered]
|
||||
|
||||
[table
|
||||
[[Syntax] [Code]]
|
||||
[[Pipe] [`rng | boost::adaptors::adjacent_filtered(bi_pred)`]]
|
||||
[[Function] [`boost::adaptors::adjacent_filter(rng, bi_pred)`]]
|
||||
]
|
||||
|
||||
* [*Precondition:] The `value_type` of the range is convertible to both argument types of `bi_pred`.
|
||||
* [*Postcondition:] For all adjacent elements `[x,y]` in the returned range, `bi_pred(x,y)` is `true`.
|
||||
* [*Throws:] Whatever the copy constructor of `bi_pred` might throw.
|
||||
* [*Range Category:] `SinglePassRange`
|
||||
|
||||
[section:adjacent_filtered_example adjacent_filtered example]
|
||||
``
|
||||
#include <boost/range/adaptor/adjacent_filtered.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,1,2,2,2,3,4,5,6;
|
||||
|
||||
boost::copy(
|
||||
input | adjacent_filtered(std::not_equal_to<int>()),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
``
|
||||
[endsect]
|
||||
|
||||
This would produce the output:
|
||||
``
|
||||
1,2,3,4,5,6
|
||||
``
|
||||
[endsect]
|
||||
|
||||
|
93
doc/reference/adaptors/copied.html
Executable file
93
doc/reference/adaptors/copied.html
Executable file
@ -0,0 +1,93 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Boost.Range Range Adaptors </title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<table border="0" >
|
||||
<tr>
|
||||
<td ><img src="../../../boost.png" border="0" /></td>
|
||||
<td ><h1 align="center">Boost.Range </h1></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2> Range Adaptors </h2>
|
||||
|
||||
<hr />
|
||||
<a name="copied"></a>
|
||||
<h4><code>copied</code></h4>
|
||||
<blockquote>
|
||||
<pre>rng | boost::adaptors::copied( n, m )</pre>
|
||||
<pre>boost::make_copied_range( rng, n, m )</pre>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Precondition:</b>
|
||||
<code>0 <= n && n <= m && m < distance(rng)</code>
|
||||
</li>
|
||||
<li>
|
||||
<b>Returns:</b>
|
||||
A new <code>iterator_range</code> that holds the sliced range
|
||||
<code>[n,m)</code> of the original range.
|
||||
</li>
|
||||
<li>
|
||||
<b>Range Category:</b>
|
||||
RandomAccessRange
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<hr />
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
<span class="keyword">#include</span> <boost/range/adaptor/copied.hpp>
|
||||
<span class="keyword">#include</span> <boost/range/algorithm/copy.hpp>
|
||||
<span class="keyword">#include</span> <boost/assign.hpp>
|
||||
<span class="keyword">#include</span> <algorithm>
|
||||
<span class="keyword">#include</span> <iostream>
|
||||
<span class="keyword">#include</span> <vector>
|
||||
|
||||
<span class="keyword">int</span> main(<span class="keyword">int</span> argc, <span class="keyword">const char</span>* argv[])
|
||||
{
|
||||
<span class="keyword">using namespace</span> boost::assign;
|
||||
<span class="keyword">using namespace</span> boost::adaptors;
|
||||
|
||||
std::vector<<span class="keyword">int</span>> input;
|
||||
input += 1,2,3,4,5,6,7,8,9,10;
|
||||
|
||||
boost::copy(
|
||||
input | copied(1, 5),
|
||||
std::ostream_iterator<<span class="keyword">int</span>>(std::cout, ","));
|
||||
|
||||
<span class="keyword">return</span> 0;
|
||||
}
|
||||
</pre>
|
||||
<p>
|
||||
This would produce the output:
|
||||
<code>2,3,4,5</code>
|
||||
</p>
|
||||
<hr />
|
||||
<p>
|
||||
(C) Copyright Neil Groves 2009
|
||||
(C) Copyright Thorsten Ottosen 2003-2004
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
</body>
|
||||
</html>
|
||||
|
45
doc/reference/adaptors/copied.qbk
Normal file
45
doc/reference/adaptors/copied.qbk
Normal file
@ -0,0 +1,45 @@
|
||||
[section:copied copied]
|
||||
|
||||
[table
|
||||
[[Syntax] [Code]]
|
||||
[[Pipe] [`rng | boost::adaptors::copied(n, m)`]]
|
||||
[[Function] [`boost::adaptors::copy(rng, n, m)`]]
|
||||
]
|
||||
|
||||
* [*Precondition:] `0 <= n && n <= m && m < distance(rng)`
|
||||
* [*Returns:] A new `iterator_range` that holds the sliced range `[n,m)` of the original range.
|
||||
* [*Range Category:] `RandomAccessRange`
|
||||
|
||||
[section:copied_example copied example]
|
||||
``
|
||||
#include <boost/range/adaptor/copied.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::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9,10;
|
||||
|
||||
boost::copy(
|
||||
input | copied(1, 5),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
``
|
||||
[endsect]
|
||||
|
||||
This would produce the output:
|
||||
``
|
||||
2,3,4,5
|
||||
``
|
||||
[endsect]
|
||||
|
||||
|
23
doc/reference/adaptors/examples/adjacent_filtered.cpp
Normal file
23
doc/reference/adaptors/examples/adjacent_filtered.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include <boost/range/adaptor/adjacent_filtered.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <functinoal>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,1,2,2,2,3,4,5,6;
|
||||
|
||||
boost::copy(
|
||||
input | adjacent_filtered(std::not_equal_to<int>()),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
22
doc/reference/adaptors/examples/copied.cpp
Normal file
22
doc/reference/adaptors/examples/copied.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include <boost/range/adaptor/copied.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::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9,10;
|
||||
|
||||
boost::copy(
|
||||
input | copied(1, 5),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
27
doc/reference/adaptors/examples/filtered.cpp
Normal file
27
doc/reference/adaptors/examples/filtered.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include <boost/range/adaptor/filtered.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
struct is_even
|
||||
{
|
||||
bool operator()(int x) const { return x % 2 == 0; }
|
||||
};
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
boost::copy(
|
||||
input | filtered(is_even()),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
36
doc/reference/adaptors/examples/indexed.cpp
Normal file
36
doc/reference/adaptors/examples/indexed.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include <boost/range/adaptor/indexed.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
template<typename Iterator>
|
||||
void display_element_and_index(Iterator first, Iterator last)
|
||||
{
|
||||
for (Iterator it = first; it != last; ++it)
|
||||
{
|
||||
std::cout << "Element = " << *it
|
||||
<< " Index = " << it.index() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename SinglePassRange>
|
||||
void display_element_and_index(const SinglePassRange& rng)
|
||||
{
|
||||
display_element_and_index(boost::begin(rng), boost::end(rng));
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 10,20,30,40,50,60,70,80,90;
|
||||
|
||||
display_element_and_index( input | indexed(0) );
|
||||
|
||||
return 0;
|
||||
]
|
||||
|
23
doc/reference/adaptors/examples/indirected.cpp
Normal file
23
doc/reference/adaptors/examples/indirected.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include <boost/range/adaptor/indirected.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<boost::shared_ptr<int> > input;
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
input.push_back(boost::shared_ptr<int>(new int(i)));
|
||||
|
||||
boost::copy(
|
||||
input | indirected,
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
24
doc/reference/adaptors/examples/map_keys.cpp
Normal file
24
doc/reference/adaptors/examples/map_keys.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include <boost/range/adaptor/map.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::map<int, int> input;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
input.insert(std::make_pair(i, i * 10));
|
||||
|
||||
boost::copy(
|
||||
input | map_keys,
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
24
doc/reference/adaptors/examples/map_values.cpp
Normal file
24
doc/reference/adaptors/examples/map_values.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include <boost/range/adaptor/map.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::map<int, int> input;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
input.insert(std::make_pair(i, i * 10));
|
||||
|
||||
boost::copy(
|
||||
input | map_values,
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
22
doc/reference/adaptors/examples/replaced.cpp
Normal file
22
doc/reference/adaptors/examples/replaced.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include <boost/range/adaptor/replaced.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;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,2,5,2,7,2,9;
|
||||
|
||||
boost::copy(
|
||||
input | replaced(2, 10),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
26
doc/reference/adaptors/examples/replaced_if.cpp
Normal file
26
doc/reference/adaptors/examples/replaced_if.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include <boost/range/adaptor/replaced_if.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
struct is_even
|
||||
{
|
||||
bool operator()(int x) const { return x % 2 == 0; }
|
||||
};
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
boost::copy(
|
||||
input | replaced_if(is_even(), 10),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
22
doc/reference/adaptors/examples/reversed.cpp
Normal file
22
doc/reference/adaptors/examples/reversed.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include <boost/range/adaptor/reversed.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;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
boost::copy(
|
||||
input | reversed,
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
22
doc/reference/adaptors/examples/sliced.cpp
Normal file
22
doc/reference/adaptors/examples/sliced.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include <boost/range/adaptor/sliced.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;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
boost::copy(
|
||||
input | sliced(2, 5),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
22
doc/reference/adaptors/examples/strided.cpp
Normal file
22
doc/reference/adaptors/examples/strided.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include <boost/range/adaptor/strided.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;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9,10;
|
||||
|
||||
boost::copy(
|
||||
input | strided(2),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
19
doc/reference/adaptors/examples/tokenized.cpp
Normal file
19
doc/reference/adaptors/examples/tokenized.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#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;
|
||||
}
|
28
doc/reference/adaptors/examples/transformed.cpp
Normal file
28
doc/reference/adaptors/examples/transformed.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include <boost/range/adaptor/transformed.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/range/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
struct double_int
|
||||
{
|
||||
typedef int result_type;
|
||||
int operator()(int x) const { return x * 2; }
|
||||
};
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9,10;
|
||||
|
||||
boost::copy(
|
||||
input | transformed(double_int()),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
22
doc/reference/adaptors/examples/uniqued.cpp
Normal file
22
doc/reference/adaptors/examples/uniqued.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include <boost/range/adaptor/uniqued.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::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,1,2,2,2,3,4,5,6;
|
||||
|
||||
boost::copy(
|
||||
input | uniqued,
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
108
doc/reference/adaptors/filtered.html
Executable file
108
doc/reference/adaptors/filtered.html
Executable file
@ -0,0 +1,108 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Boost.Range Range Adaptors </title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<table border="0" >
|
||||
<tr>
|
||||
<td ><img src="../../../boost.png" border="0" /></td>
|
||||
<td ><h1 align="center">Boost.Range </h1></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2> Range Adaptors </h2>
|
||||
|
||||
<hr />
|
||||
<a name="filtered"></a>
|
||||
<h4><code>filtered</code></h4>
|
||||
<blockquote>
|
||||
<pre>rng | boost::adaptors::filtered( pred )</pre>
|
||||
<pre>boost::make_filtered_range( rng, pred )</pre>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Precondition:</b>
|
||||
The value-type of the range is convertible to the argument type of
|
||||
<code>pred</code>.
|
||||
</li>
|
||||
<li>
|
||||
<b>Postcondition:</b>
|
||||
For all elements <code>x</code> in the returned range,
|
||||
<code>pred(x)</code> is <code>true</code>
|
||||
</li>
|
||||
<li>
|
||||
<b>Throws:</b>
|
||||
Whatever the copy-constructor of pred might throw.
|
||||
</li>
|
||||
<li>
|
||||
<b>Range Category:</b>
|
||||
ForwardRange
|
||||
</li>
|
||||
<li>
|
||||
<b>Returned Range Category:</b>
|
||||
ForwardRange
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<hr />
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
<span class="keyword">#include</span> <boost/range/adaptor/filtered.hpp>
|
||||
<span class="keyword">#include</span> <boost/range/algorithm/copy.hpp>
|
||||
<span class="keyword">#include</span> <boost/assign.hpp>
|
||||
<span class="keyword">#include</span> <algorithm>
|
||||
<span class="keyword">#include</span> <iostream>
|
||||
<span class="keyword">#include</span> <vector>
|
||||
|
||||
<span class="keyword">struct</span> is_even
|
||||
{
|
||||
<span class="keyword">bool operator</span>()(<span class="keyword">int</span> x) <span class="keyword">const</span> { <span class="keyword">return</span> x % 2 == 0; }
|
||||
};
|
||||
|
||||
<span class="keyword">int</span> main(<span class="keyword">int</span> argc, <span class="keyword">const char</span>* argv[])
|
||||
{
|
||||
<span class="keyword">using namespace</span> boost::assign;
|
||||
<span class="keyword">using namespace</span> boost::adaptors;
|
||||
|
||||
std::vector<<span class="keyword">int</span>> input;
|
||||
input += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
boost::copy(
|
||||
input | filtered(is_even()),
|
||||
std::ostream_iterator<<span class="keyword">int</span>>(std::cout, ","));
|
||||
|
||||
<span class="keyword">return</span> 0;
|
||||
}
|
||||
</pre>
|
||||
<p>
|
||||
This would produce the output: <br />
|
||||
<code>2,4,6,8</code>
|
||||
</p>
|
||||
|
||||
<hr />
|
||||
<p>
|
||||
(C) Copyright Neil Groves 2009
|
||||
(C) Copyright Thorsten Ottosen 2003-2004
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
</body>
|
||||
</html>
|
||||
|
50
doc/reference/adaptors/filtered.qbk
Normal file
50
doc/reference/adaptors/filtered.qbk
Normal file
@ -0,0 +1,50 @@
|
||||
[section:filtered filtered]
|
||||
|
||||
[table
|
||||
[[Syntax] [Code]]
|
||||
[[Pipe] [`rng | boost::adaptors::filtered(pred)`]]
|
||||
[[Function] [`boost::adaptors::filter(rng, pred)`]]
|
||||
]
|
||||
|
||||
* [*Precondition:] The `value_type` of the range is convertible to the argument type of `pred`.
|
||||
* [*Postcondition:] For all adjacent elements `[x]` in the returned range, `pred(x)` is `true`.
|
||||
* [*Throws:] Whatever the copy constructor of `pred` might throw.
|
||||
* [*Range Category:] `ForwardRange`
|
||||
* [*Returned Range Category:] `ForwardRange`
|
||||
|
||||
[section:filtered_example filtered example]
|
||||
``
|
||||
#include <boost/range/adaptor/filtered.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
struct is_even
|
||||
{
|
||||
bool operator()( int x ) const { return x % 2 == 0; }
|
||||
};
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
boost::copy(
|
||||
input | filtered(is_even()),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
}
|
||||
``
|
||||
[endsect]
|
||||
|
||||
This would produce the output:
|
||||
``
|
||||
2,4,6,8
|
||||
``
|
||||
[endsect]
|
||||
|
||||
|
117
doc/reference/adaptors/indexed.html
Executable file
117
doc/reference/adaptors/indexed.html
Executable file
@ -0,0 +1,117 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Boost.Range Range Adaptors </title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<table border="0" >
|
||||
<tr>
|
||||
<td ><img src="../../../boost.png" border="0" /></td>
|
||||
<td ><h1 align="center">Boost.Range </h1></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2> Range Adaptors </h2>
|
||||
|
||||
<hr />
|
||||
<a name="indexed"></a>
|
||||
<h4><code>indexed</code></h4>
|
||||
<blockquote>
|
||||
<pre>rng | boost::adaptors::indexed</pre>
|
||||
<pre>boost::make_indexed_range( rng )</pre>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Returns:</b>
|
||||
A range adapted to return both the element and the associated
|
||||
index.
|
||||
The returned range consists of iterators that have in addition
|
||||
to the usual iterator member functions an
|
||||
<code>index()</code> member function that returns the appropriate
|
||||
index for the element in the sequence corresponding with the
|
||||
iterator.
|
||||
</li>
|
||||
<li>
|
||||
<b>Range Category:</b>
|
||||
SinglePassRange
|
||||
</li>
|
||||
</ul>
|
||||
<hr />
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
<span class="keyword">#include</span> <boost/range/adaptor/indexed.hpp>
|
||||
<span class="keyword">#include</span> <boost/range/algorithm/copy.hpp>
|
||||
<span class="keyword">#include</span> <boost/assign.hpp>
|
||||
<span class="keyword">#include</span> <algorithm>
|
||||
<span class="keyword">#include</span> <iostream>
|
||||
<span class="keyword">#include</span> <vector>
|
||||
|
||||
<span class="keyword">template</span><<span class="keyword">class</span> Iterator>
|
||||
void display_element_and_index(Iterator first, Iterator last)
|
||||
{
|
||||
<span class="keyword">for</span> (Iterator it = first; it != last; ++it)
|
||||
{
|
||||
std::cout << "Element = " << *it
|
||||
<< " Index = " << it.index() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
<span class="keyword">template</span><<span class="keyword">class</span> SinglePassRange>
|
||||
void display_element_and_index(<span class="keyword">const</span> SinglePassRange& rng)
|
||||
{
|
||||
display_element_and_index(boost::begin(rng), boost::end(rng));
|
||||
}
|
||||
|
||||
<span class="keyword">int</span> main(<span class="keyword">int</span> argc, <span class="keyword">const char</span>* argv[])
|
||||
{
|
||||
<span class="keyword">using namespace</span> boost::assign;
|
||||
<span class="keyword">using namespace</span> boost::adaptors;
|
||||
|
||||
std::vector<<span class="keyword">int</span>> input;
|
||||
input += 10,20,30,40,50,60,70,80,90;
|
||||
|
||||
display_element_and_index( input | indexed(0) );
|
||||
|
||||
<span class="keyword">return</span> 0;
|
||||
}
|
||||
</pre>
|
||||
<p>
|
||||
This produces the output: <br />
|
||||
<code>
|
||||
Element = 10 Index = 0 <br />
|
||||
Element = 20 Index = 1 <br />
|
||||
Element = 30 Index = 2 <br />
|
||||
Element = 40 Index = 3 <br />
|
||||
Element = 50 Index = 4 <br />
|
||||
Element = 60 Index = 5 <br />
|
||||
Element = 70 Index = 6 <br />
|
||||
Element = 80 Index = 7 <br />
|
||||
Element = 90 Index = 8 <br />
|
||||
</code>
|
||||
</p>
|
||||
<hr />
|
||||
<p>
|
||||
(C) Copyright Neil Groves 2009
|
||||
(C) Copyright Thorsten Ottosen 2003-2004
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
</body>
|
||||
</html>
|
||||
|
86
doc/reference/adaptors/indexed.qbk
Normal file
86
doc/reference/adaptors/indexed.qbk
Normal file
@ -0,0 +1,86 @@
|
||||
[section:indexed indexed]
|
||||
|
||||
[table
|
||||
[[Syntax] [Code]]
|
||||
[[Pipe] [`rng | boost::adaptors::indexed`]]
|
||||
[[Function] [`boost::adaptors::index(rng)`]]
|
||||
]
|
||||
|
||||
* [*Returns:] A range adapted to return both the element and the associated index. The returned range consists of iterators that have in addition to the usual iterator member functions an `index()` member function that returns the appropriate index for the element in the sequence corresponding with the iterator.
|
||||
* [*Range Category:] `SinglePassRange`
|
||||
|
||||
[section:indexed_example indexed example]
|
||||
``
|
||||
#include <boost/range/adaptor/indexed.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
template<class Iterator>
|
||||
void display_element_and_index(Iterator first, Iterator last)
|
||||
{
|
||||
for (Iterator it = first; it != last; ++it)
|
||||
{
|
||||
std::cout << "Element = " << *it << " Index = " << it.index() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
template<class SinglePassRange>
|
||||
void display_element_and_index(const SinglePassRange& rng)
|
||||
{
|
||||
display_element_and_index(boost::begin(rng), boost::end(rng));
|
||||
}
|
||||
|
||||
template<class Iterator1, class Iterator2>
|
||||
void check_element_and_index(
|
||||
Iterator1 test_first,
|
||||
Iterator1 test_last,
|
||||
Iterator2 reference_first,
|
||||
Iterator2 reference_last)
|
||||
{
|
||||
BOOST_CHECK_EQUAL( std::distance(test_first, test_last),
|
||||
std::distance(reference_first, reference_last) );
|
||||
|
||||
int reference_index = 0;
|
||||
|
||||
Iterator1 test_it = test_first;
|
||||
Iterator2 reference_it = reference_first;
|
||||
for (; test_it != test_last; ++test_it, ++reference_it, ++reference_index)
|
||||
{
|
||||
BOOST_CHECK_EQUAL( *test_it, *reference_it );
|
||||
BOOST_CHECK_EQUAL( test_it.index(), reference_index );
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 10,20,30,40,50,60,70,80,90;
|
||||
|
||||
display_element_and_index( input | indexed(0) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
``
|
||||
[endsect]
|
||||
|
||||
This would produce the output:
|
||||
``
|
||||
Element = 10 Index = 0
|
||||
Element = 20 Index = 1
|
||||
Element = 30 Index = 2
|
||||
Element = 40 Index = 3
|
||||
Element = 50 Index = 4
|
||||
Element = 60 Index = 5
|
||||
Element = 70 Index = 6
|
||||
Element = 80 Index = 7
|
||||
Element = 90 Index = 8
|
||||
``
|
||||
[endsect]
|
||||
|
||||
|
95
doc/reference/adaptors/indirected.html
Executable file
95
doc/reference/adaptors/indirected.html
Executable file
@ -0,0 +1,95 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Boost.Range Range Adaptors </title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<table border="0" >
|
||||
<tr>
|
||||
<td ><img src="../../../boost.png" border="0" /></td>
|
||||
<td ><h1 align="center">Boost.Range </h1></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2> Range Adaptors </h2>
|
||||
|
||||
<hr />
|
||||
<a name="indirected"></a>
|
||||
<h4><code>indirected</code></h4>
|
||||
<blockquote>
|
||||
<pre>rng | boost::adaptors::indirected</pre>
|
||||
<pre>boost::make_indirected_range( rng )</pre>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Precondition:</b>
|
||||
The value-type of the range defines unary <code>operator*()</code>
|
||||
</li>
|
||||
<li>
|
||||
<b>Postcondition:</b>
|
||||
For all elements <code>x</code> in the returned range,
|
||||
<code>x</code> is the result of <code>*y</code> where
|
||||
<code>y</code> is the corresponding element in the original range.
|
||||
</li>
|
||||
<li>
|
||||
<b>Range Category:</b>
|
||||
SinglePassRange
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<hr />
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
<span class="keyword">#include</span> <boost/range/adaptor/indirected.hpp>
|
||||
<span class="keyword">#include</span> <boost/range/algorithm/copy.hpp>
|
||||
<span class="keyword">#include</span> <boost/shared_ptr.hpp>
|
||||
<span class="keyword">#include</span> <algorithm>
|
||||
<span class="keyword">#include</span> <iostream>
|
||||
<span class="keyword">#include</span> <vector>
|
||||
|
||||
<span class="keyword">int</span> main(<span class="keyword">int</span> argc, <span class="keyword">const char</span>* argv[])
|
||||
{
|
||||
<span class="keyword">using namespace</span> boost::adaptors;
|
||||
|
||||
std::vector<boost::shared_ptr<<span class="keyword">int</span>> > input;
|
||||
|
||||
<span class="keyword">for</span> (<span class="keyword">int</span> i = 0; i < 10; ++i)
|
||||
input.push_back(boost::shared_ptr<<span class="keyword">int</span>>(<span class="keyword">new int</span>(i)));
|
||||
|
||||
boost::copy(
|
||||
input | indirected,
|
||||
std::ostream_iterator<<span class="keyword">int</span>>(std::cout, ","));
|
||||
|
||||
<span class="keyword">return</span> 0;
|
||||
}
|
||||
</pre>
|
||||
<p>
|
||||
This produces the output: <br />
|
||||
<code>0,1,2,3,4,5,6,7,8,9</code>
|
||||
</p>
|
||||
<hr />
|
||||
<p>
|
||||
(C) Copyright Neil Groves 2009
|
||||
(C) Copyright Thorsten Ottosen 2003-2004
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
</body>
|
||||
</html>
|
||||
|
46
doc/reference/adaptors/indirected.qbk
Normal file
46
doc/reference/adaptors/indirected.qbk
Normal file
@ -0,0 +1,46 @@
|
||||
[section:indirected indirected]
|
||||
|
||||
[table
|
||||
[[Syntax] [Code]]
|
||||
[[Pipe] [`rng | boost::adaptors::indirected`]]
|
||||
[[Function] [`boost::adaptors::indirect(rng)`]]
|
||||
]
|
||||
|
||||
* [*Precondition:] The `value_type` of the range defines unary `operator*()`
|
||||
* [*Postcondition:] For all elements `x` in the returned range, `x` is the result of `*y` where `y` is the corresponding element in the original range.
|
||||
* [*Range Category:] `SinglePassRange`
|
||||
|
||||
[section:indirected_example indirected example]
|
||||
``
|
||||
#include <boost/range/adaptor/indirected.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<boost::shared_ptr<int> > input;
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
input.push_back(boost::shared_ptr<int>(new int(i)));
|
||||
|
||||
boost::copy(
|
||||
input | indirected,
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
``
|
||||
[endsect]
|
||||
|
||||
This would produce the output:
|
||||
``
|
||||
0,1,2,3,4,5,6,7,8,9
|
||||
``
|
||||
[endsect]
|
||||
|
||||
|
99
doc/reference/adaptors/map_keys.html
Executable file
99
doc/reference/adaptors/map_keys.html
Executable file
@ -0,0 +1,99 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Boost.Range Range Adaptors </title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<table border="0" >
|
||||
<tr>
|
||||
<td ><img src="../../../boost.png" border="0" /></td>
|
||||
<td ><h1 align="center">Boost.Range </h1></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2> Range Adaptors </h2>
|
||||
|
||||
<hr />
|
||||
<a name="map_keys"></a>
|
||||
<h4><code>map_keys</code></h4>
|
||||
<blockquote>
|
||||
<pre>rng | boost::adaptors::map_keys</pre>
|
||||
<pre>boost::make_map_key_range( rng )</pre>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Precondition:</b>
|
||||
The value-type of the range is an instantiation of std::pair.
|
||||
</li>
|
||||
<li>
|
||||
<b>Postcondition:</b>
|
||||
For all elements <code>x</code> in the returned range,
|
||||
<code>x</code> is the result of <code>y.first</code> where
|
||||
<code>y</code> is the corresponding element in the original range.
|
||||
</li>
|
||||
<li>
|
||||
<b>Range Category:</b>
|
||||
SinglePassRange
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<hr />
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
<span class="keyword">#include</span> <boost/range/adaptor/map.hpp>
|
||||
<span class="keyword">#include</span> <boost/range/algorithm/copy.hpp>
|
||||
<span class="keyword">#include</span> <boost/assign.hpp>
|
||||
<span class="keyword">#include</span> <algorithm>
|
||||
<span class="keyword">#include</span> <iostream>
|
||||
<span class="keyword">#include</span> <map>
|
||||
<span class="keyword">#include</span> <vector>
|
||||
|
||||
<span class="keyword">int</span> main(<span class="keyword">int</span> argc, <span class="keyword">const char</span>* argv[])
|
||||
{
|
||||
<span class="keyword">using namespace</span> boost::assign;
|
||||
<span class="keyword">using namespace</span> boost::adaptors;
|
||||
|
||||
std::map<<span class="keyword">int</span>,<span class="keyword">int</span>> input;
|
||||
<span class="keyword">for</span> (<span class="keyword">int</span> i = 0; i < 10; ++i)
|
||||
input.insert(std::make_pair(i, i * 10));
|
||||
|
||||
boost::copy(
|
||||
input | map_keys,
|
||||
std::ostream_iterator<<span class="keyword">int</span>>(std::cout, ","));
|
||||
|
||||
<span class="keyword">return</span> 0;
|
||||
}
|
||||
</pre>
|
||||
<p>
|
||||
This produces the output: <br />
|
||||
<code>
|
||||
0,1,2,3,4,5,6,7,8,9
|
||||
</code>
|
||||
</p>
|
||||
|
||||
<hr />
|
||||
<p>
|
||||
(C) Copyright Neil Groves 2009
|
||||
(C) Copyright Thorsten Ottosen 2003-2004
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
</body>
|
||||
</html>
|
||||
|
47
doc/reference/adaptors/map_keys.qbk
Normal file
47
doc/reference/adaptors/map_keys.qbk
Normal file
@ -0,0 +1,47 @@
|
||||
[section:map_keys map_keys]
|
||||
|
||||
[table
|
||||
[[Syntax] [Code]]
|
||||
[[Pipe] [`rng | boost::adaptors::map_keys`]]
|
||||
[[Function] [`boost::adaptors::keys(rng)`]]
|
||||
]
|
||||
|
||||
* [*Precondition:] The `value_type` of the range is an instantiation of `std::pair`.
|
||||
* [*Postcondition:] For all elements `x` in the returned range, `x` is the result of `y.first` where `y` is the corresponding element in the original range.
|
||||
* [*Range Category:] `SinglePassRange`
|
||||
|
||||
[section:map_keys_example map_keys example]
|
||||
``
|
||||
#include <boost/range/adaptor/map.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::map<int,int> input;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
input.insert(std::make_pair(i, i * 10));
|
||||
|
||||
boost::copy(
|
||||
input | map_keys,
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
``
|
||||
[endsect]
|
||||
|
||||
This would produce the output:
|
||||
``
|
||||
0,1,2,3,4,5,6,7,8,9
|
||||
``
|
||||
[endsect]
|
||||
|
||||
|
98
doc/reference/adaptors/map_values.html
Executable file
98
doc/reference/adaptors/map_values.html
Executable file
@ -0,0 +1,98 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Boost.Range Range Adaptors </title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<table border="0" >
|
||||
<tr>
|
||||
<td ><img src="../../../boost.png" border="0" /></td>
|
||||
<td ><h1 align="center">Boost.Range </h1></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2> Range Adaptors </h2>
|
||||
|
||||
<hr />
|
||||
<a name="map_values"></a>
|
||||
<h4><code>map_values</code></h4>
|
||||
<blockquote>
|
||||
<pre>rng | boost::adaptors::map_values</pre>
|
||||
<pre>boost::make_map_value_range( rng )</pre>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Precondition:</b>
|
||||
The value-type of the range is an instantiation of std::pair.
|
||||
</li>
|
||||
<li>
|
||||
<b>Postcondition:</b>
|
||||
For all elements <code>x</code> in the returned range,
|
||||
<code>x</code> is the result of <code>y.second</code> where
|
||||
<code>y</code> is the corresponding element in the original range.
|
||||
</li>
|
||||
<li>
|
||||
<b>Range Category:</b>
|
||||
SinglePassRange
|
||||
</li>
|
||||
</ul>
|
||||
<hr />
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
<span class="keyword">#include</span> <boost/range/adaptor/map.hpp>
|
||||
<span class="keyword">#include</span> <boost/range/algorithm/copy.hpp>
|
||||
<span class="keyword">#include</span> <boost/assign.hpp>
|
||||
<span class="keyword">#include</span> <algorithm>
|
||||
<span class="keyword">#include</span> <iostream>
|
||||
<span class="keyword">#include</span> <map>
|
||||
<span class="keyword">#include</span> <vector>
|
||||
|
||||
<span class="keyword">int</span> main(<span class="keyword">int</span> argc, <span class="keyword">const char</span>* argv[])
|
||||
{
|
||||
<span class="keyword">using namespace</span> boost::assign;
|
||||
<span class="keyword">using namespace</span> boost::adaptors;
|
||||
|
||||
std::map<<span class="keyword">int</span>,<span class="keyword">int</span>> input;
|
||||
<span class="keyword">for</span> (<span class="keyword">int</span> i = 0; i < 10; ++i)
|
||||
input.insert(std::make_pair(i, i * 10));
|
||||
|
||||
boost::copy(
|
||||
input | map_values,
|
||||
std::ostream_iterator<<span class="keyword">int</span>>(std::cout, ","));
|
||||
|
||||
<span class="keyword">return</span> 0;
|
||||
}
|
||||
</pre>
|
||||
<p>
|
||||
This produces the output: <br />
|
||||
<code>
|
||||
0,10,20,30,40,50,60,70,80,90
|
||||
</code>
|
||||
</p>
|
||||
|
||||
<hr />
|
||||
<p>
|
||||
(C) Copyright Neil Groves 2009
|
||||
(C) Copyright Thorsten Ottosen 2003-2004
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
</body>
|
||||
</html>
|
||||
|
47
doc/reference/adaptors/map_values.qbk
Normal file
47
doc/reference/adaptors/map_values.qbk
Normal file
@ -0,0 +1,47 @@
|
||||
[section:map_values map_values]
|
||||
|
||||
[table
|
||||
[[Syntax] [Code]]
|
||||
[[Pipe] [`rng | boost::adaptors::map_values`]]
|
||||
[[Function] [`boost::adaptors::values(rng)`]]
|
||||
]
|
||||
|
||||
* [*Precondition:] The `value_type` of the range is an instantiation of `std::pair`.
|
||||
* [*Postcondition:] For all elements `x` in the returned range, `x` is the result of `y.second` where `y` is the corresponding element in the original range.
|
||||
* [*Range Category:] `SinglePassRange`
|
||||
|
||||
[section:map_values_example map_values example]
|
||||
``
|
||||
#include <boost/range/adaptor/map.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::map<int,int> input;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
input.insert(std::make_pair(i, i * 10));
|
||||
|
||||
boost::copy(
|
||||
input | map_values,
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
``
|
||||
[endsect]
|
||||
|
||||
This would produce the output:
|
||||
``
|
||||
0,10,20,30,40,50,60,70,80,90
|
||||
``
|
||||
[endsect]
|
||||
|
||||
|
107
doc/reference/adaptors/replaced.html
Executable file
107
doc/reference/adaptors/replaced.html
Executable file
@ -0,0 +1,107 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Boost.Range Range Adaptors </title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<table border="0" >
|
||||
<tr>
|
||||
<td ><img src="../../../boost.png" border="0" /></td>
|
||||
<td ><h1 align="center">Boost.Range </h1></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2> Range Adaptors </h2>
|
||||
|
||||
<hr />
|
||||
<a name="replaced"></a>
|
||||
<h4><code>replaced</code></h4>
|
||||
<blockquote>
|
||||
<pre>rng | boost::adaptors::replaced( new_value, old_value )</pre>
|
||||
<pre>boost::make_replaced_range( rng, new_value, old_value )</pre>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Precondition:</b>
|
||||
<ul>
|
||||
<li>
|
||||
<code>new_value</code> is convertible to the value-type of
|
||||
the range.
|
||||
</li>
|
||||
<li>
|
||||
<code>old_value</code> is convertible to the value-type of
|
||||
the range.
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<b>Postcondition:</b>
|
||||
For all elements <code>x</code> in the returned range, the value
|
||||
<code>x</code> is equal to the value of
|
||||
<code>(y == old_value) ? new_value : y</code>
|
||||
where <code>y</code> is the corresponding element in the original
|
||||
range.
|
||||
</li>
|
||||
<li>
|
||||
<b>Range Category:</b>
|
||||
ForwardRange
|
||||
</li>
|
||||
</ul>
|
||||
<hr />
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
<span class="keyword">#include</span> <boost/range/adaptor/replaced.hpp>
|
||||
<span class="keyword">#include</span> <boost/range/algorithm/copy.hpp>
|
||||
<span class="keyword">#include</span> <boost/assign.hpp>
|
||||
<span class="keyword">#include</span> <algorithm>
|
||||
<span class="keyword">#include</span> <iostream>
|
||||
<span class="keyword">#include</span> <vector>
|
||||
|
||||
<span class="keyword">int</span> main(<span class="keyword">int</span> argc, <span class="keyword">const char</span>* argv[])
|
||||
{
|
||||
<span class="keyword">using namespace</span> boost::adaptors;
|
||||
<span class="keyword">using namespace</span> boost::assign;
|
||||
|
||||
std::vector<<span class="keyword">int</span>> input;
|
||||
input += 1,2,3,2,5,2,7,2,9;
|
||||
|
||||
boost::copy(
|
||||
input | replaced(2, 10),
|
||||
std::ostream_iterator<<span class="keyword">int</span>>(std::cout, ","));
|
||||
|
||||
<span class="keyword">return</span> 0;
|
||||
}
|
||||
</pre>
|
||||
<p>
|
||||
This produces the output: <br />
|
||||
<code>
|
||||
1,10,3,10,5,10,7,10,9
|
||||
</code>
|
||||
</p>
|
||||
|
||||
<hr />
|
||||
<p>
|
||||
(C) Copyright Neil Groves 2009
|
||||
(C) Copyright Thorsten Ottosen 2003-2004
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
</body>
|
||||
</html>
|
||||
|
47
doc/reference/adaptors/replaced.qbk
Normal file
47
doc/reference/adaptors/replaced.qbk
Normal file
@ -0,0 +1,47 @@
|
||||
[section:replaced replaced]
|
||||
|
||||
[table
|
||||
[[Syntax] [Code]]
|
||||
[[Pipe] [`rng | boost::adaptors::replaced(new_value, old_value)`]]
|
||||
[[Function] [`boost::adaptors::replace(rng, new_value, old_value)`]]
|
||||
]
|
||||
|
||||
* [*Precondition:]
|
||||
* `new_value` is convertible to the `value_type` of the range.
|
||||
* `old_value` is convertible to the `value_type` of the range.
|
||||
* [*Postcondition:] For all elements `x` in the returned range, the value `x` is equal to the value of `(y == old_value) ? new_value : y` where `y` is the corresponding element in the original range.
|
||||
* [*Range Category:] `ForwardRange`
|
||||
|
||||
[section:replaced_example replaced example]
|
||||
``
|
||||
#include <boost/range/adaptor/replaced.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;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,2,5,2,7,2,9;
|
||||
|
||||
boost::copy(
|
||||
input | replaced(2, 10),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
``
|
||||
[endsect]
|
||||
|
||||
This would produce the output:
|
||||
``
|
||||
1,10,3,10,5,10,7,10,9
|
||||
``
|
||||
[endsect]
|
||||
|
||||
|
114
doc/reference/adaptors/replaced_if.html
Executable file
114
doc/reference/adaptors/replaced_if.html
Executable file
@ -0,0 +1,114 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Boost.Range Range Adaptors </title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<table border="0" >
|
||||
<tr>
|
||||
<td ><img src="../../../boost.png" border="0" /></td>
|
||||
<td ><h1 align="center">Boost.Range </h1></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2> Range Adaptors </h2>
|
||||
|
||||
<hr />
|
||||
<a name="replaced_if"></a>
|
||||
<h4><code>replaced_if</code></h4>
|
||||
<blockquote>
|
||||
<pre>rng | boost::adaptors::replaced_if( pred, new_value )</pre>
|
||||
<pre>boost::make_replaced_if_range( rng, pred, new_value )</pre>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Precondition:</b>
|
||||
<ul>
|
||||
<li>
|
||||
The range value-type is convertible to the argument type
|
||||
of <code>pred</code>.
|
||||
</li>
|
||||
<li>
|
||||
<code>new_value</code> is convertible to the value-type
|
||||
of the range.
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<b>Postconditions:</b>
|
||||
For all elements <code>[x]</code> in the returned range, the value
|
||||
<code>x</code> is equal to the value of
|
||||
<code>pred(y) ? new_value : y</code>
|
||||
where <code>y</code> is the corresponding element in the original
|
||||
range.
|
||||
</li>
|
||||
<li>
|
||||
<b>Range Category:</b>
|
||||
ForwardRange
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<hr />
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
<span class="keyword">#include</span> <boost/range/adaptor/replaced_if.hpp>
|
||||
<span class="keyword">#include</span> <boost/range/algorithm/copy.hpp>
|
||||
<span class="keyword">#include</span> <boost/assign.hpp>
|
||||
<span class="keyword">#include</span> <algorithm>
|
||||
<span class="keyword">#include</span> <iostream>
|
||||
<span class="keyword">#include</span> <vector>
|
||||
|
||||
<span class="keyword">struct</span> is_even
|
||||
{
|
||||
<span class="keyword">bool operator</span>()(<span class="keyword">int</span> x) <span class="keyword">const</span> { <span class="keyword">return</span> x % 2 == 0; }
|
||||
};
|
||||
|
||||
<span class="keyword">int</span> main(<span class="keyword">int</span> argc, <span class="keyword">const char</span>* argv[])
|
||||
{
|
||||
<span class="keyword">using namespace</span> boost::adaptors;
|
||||
<span class="keyword">using namespace</span> boost::assign;
|
||||
|
||||
std::vector<<span class="keyword">int</span>> input;
|
||||
input += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
boost::copy(
|
||||
input | replaced_if(is_even(), 10),
|
||||
std::ostream_iterator<<span class="keyword">int</span>>(std::cout, ","));
|
||||
|
||||
<span class="keyword">return</span> 0;
|
||||
}
|
||||
|
||||
</pre>
|
||||
<p>
|
||||
This produces the output: <br />
|
||||
<code>
|
||||
1,10,3,10,5,10,7,10,9
|
||||
</code>
|
||||
</p>
|
||||
|
||||
<hr />
|
||||
<p>
|
||||
(C) Copyright Neil Groves 2009
|
||||
(C) Copyright Thorsten Ottosen 2003-2004
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
</body>
|
||||
</html>
|
||||
|
52
doc/reference/adaptors/replaced_if.qbk
Normal file
52
doc/reference/adaptors/replaced_if.qbk
Normal file
@ -0,0 +1,52 @@
|
||||
[section:replaced_if replaced_if]
|
||||
|
||||
[table
|
||||
[[Syntax] [Code]]
|
||||
[[Pipe] [`rng | boost::adaptors::replaced_if(pred, new_value)`]]
|
||||
[[Function] [`boost::adaptors::replace_if(rng, pred, new_value)`]]
|
||||
]
|
||||
|
||||
* [*Precondition:]
|
||||
* The range `value_type` is convertible to the argument type of `pred`.
|
||||
* `new_value` is convertible to the `value_type` of the range.
|
||||
* [*Postconditions:] For all elements `x` in the returned range, the value `x` is equal to the value of `pred(y) ? new_value : y` where `y` is the corresponding element in the original range.
|
||||
* [*Range Category:] `ForwardRange`
|
||||
|
||||
[section:replaced_if_example replaced_if example]
|
||||
``
|
||||
#include <boost/range/adaptor/replaced_if.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
struct is_even
|
||||
{
|
||||
bool operator()(int x) const { return x % 2 == 0; }
|
||||
};
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
boost::copy(
|
||||
input | replaced_if(is_even(), 10),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
``
|
||||
[endsect]
|
||||
|
||||
This would produce the output:
|
||||
``
|
||||
1,10,3,10,5,10,7,10,9
|
||||
``
|
||||
[endsect]
|
||||
|
||||
|
91
doc/reference/adaptors/reversed.html
Executable file
91
doc/reference/adaptors/reversed.html
Executable file
@ -0,0 +1,91 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Boost.Range Range Adaptors </title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<table border="0" >
|
||||
<tr>
|
||||
<td ><img src="../../../boost.png" border="0" /></td>
|
||||
<td ><h1 align="center">Boost.Range </h1></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2> Range Adaptors </h2>
|
||||
|
||||
<hr />
|
||||
<a name="reversed"></a>
|
||||
<h4><code>reversed</code></h4>
|
||||
<blockquote>
|
||||
<pre>rng | boost::adaptors::reversed</pre>
|
||||
<pre>boost::make_reversed_range( rng )</pre>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Returns:</b>
|
||||
A range whose iterators behave as if they were the original
|
||||
iterators wrapped in <code>reverse_iterator</code>.
|
||||
</li>
|
||||
<li>
|
||||
<b>Range Category:</b>
|
||||
BidirectionalRange
|
||||
</li>
|
||||
</ul>
|
||||
<hr />
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
<span class="keyword">#include</span> <boost/range/adaptor/reversed.hpp>
|
||||
<span class="keyword">#include</span> <boost/range/algorithm/copy.hpp>
|
||||
<span class="keyword">#include</span> <boost/assign.hpp>
|
||||
<span class="keyword">#include</span> <algorithm>
|
||||
<span class="keyword">#include</span> <iostream>
|
||||
<span class="keyword">#include</span> <vector>
|
||||
|
||||
<span class="keyword">int</span> main(<span class="keyword">int</span> argc, <span class="keyword">const char</span>* argv[])
|
||||
{
|
||||
<span class="keyword">using namespace</span> boost::adaptors;
|
||||
<span class="keyword">using namespace</span> boost::assign;
|
||||
|
||||
std::vector<<span class="keyword">int</span>> input;
|
||||
input += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
boost::copy(
|
||||
input | reversed,
|
||||
std::ostream_iterator<<span class="keyword">int</span>>(std::cout, ","));
|
||||
|
||||
<span class="keyword">return</span> 0;
|
||||
}
|
||||
</pre>
|
||||
<p>
|
||||
This produces the output: <br />
|
||||
<code>
|
||||
9,8,7,6,5,4,3,2,1
|
||||
</code>
|
||||
</p>
|
||||
|
||||
<hr />
|
||||
<p>
|
||||
(C) Copyright Neil Groves 2009
|
||||
(C) Copyright Thorsten Ottosen 2003-2004
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
</body>
|
||||
</html>
|
||||
|
44
doc/reference/adaptors/reversed.qbk
Normal file
44
doc/reference/adaptors/reversed.qbk
Normal file
@ -0,0 +1,44 @@
|
||||
[section:reversed reversed]
|
||||
|
||||
[table
|
||||
[[Syntax] [Code]]
|
||||
[[Pipe] [`rng | boost::adaptors::reversed`]]
|
||||
[[Function] [`boost::adaptors::reverse(rng)`]]
|
||||
]
|
||||
|
||||
* [*Returns:] A range whose iterators behave as if they were the original iterators wrapped in `reverse_iterator`.
|
||||
* [*Range Category:] `BidirectionalRange`
|
||||
|
||||
[section:reversed_example reversed example]
|
||||
``
|
||||
#include <boost/range/adaptor/reversed.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
void reversed_example_test()
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
boost::copy(
|
||||
input | reversed,
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
``
|
||||
[endsect]
|
||||
|
||||
This would produce the output:
|
||||
``
|
||||
9,8,7,6,5,4,3,2,1
|
||||
``
|
||||
[endsect]
|
||||
|
||||
|
94
doc/reference/adaptors/sliced.html
Executable file
94
doc/reference/adaptors/sliced.html
Executable file
@ -0,0 +1,94 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Boost.Range Range Adaptors </title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<table border="0" >
|
||||
<tr>
|
||||
<td ><img src="../../../boost.png" border="0" /></td>
|
||||
<td ><h1 align="center">Boost.Range </h1></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2> Range Adaptors </h2>
|
||||
|
||||
<hr />
|
||||
<a name="sliced"></a>
|
||||
<h4><code>sliced</code></h4>
|
||||
<blockquote>
|
||||
<pre>rng | boost::adaptors::sliced( n, m )</pre>
|
||||
<pre>boost::make_sliced_range( rng, n, m )</pre>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Precondition:</b>
|
||||
<code>0 <= n && n <= m && m < distance(rng)</code>
|
||||
</li>
|
||||
<li>
|
||||
<b>Returns:</b>
|
||||
<code>make_range(rng, n, m)</code>
|
||||
</li>
|
||||
<li>
|
||||
<b>Range Category:</b>
|
||||
RandomAccessRange
|
||||
</li>
|
||||
</ul>
|
||||
<hr />
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
<span class="keyword">#include</span> <boost/range/adaptor/sliced.hpp>
|
||||
<span class="keyword">#include</span> <boost/range/algorithm/copy.hpp>
|
||||
<span class="keyword">#include</span> <boost/assign.hpp>
|
||||
<span class="keyword">#include</span> <algorithm>
|
||||
<span class="keyword">#include</span> <iostream>
|
||||
<span class="keyword">#include</span> <vector>
|
||||
|
||||
<span class="keyword">int</span> main(<span class="keyword">int</span> argc, <span class="keyword">const char</span>* argv[])
|
||||
{
|
||||
<span class="keyword">using namespace</span> boost::adaptors;
|
||||
<span class="keyword">using namespace</span> boost::assign;
|
||||
|
||||
std::vector<<span class="keyword">int</span>> input;
|
||||
input += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
boost::copy(
|
||||
input | sliced(2, 5),
|
||||
std::ostream_iterator<<span class="keyword">int</span>>(std::cout, ","));
|
||||
|
||||
<span class="keyword">return</span> 0;
|
||||
}
|
||||
</pre>
|
||||
<p>
|
||||
This produces the output: <br />
|
||||
<code>
|
||||
3,4,5
|
||||
</code>
|
||||
</p>
|
||||
|
||||
<hr />
|
||||
<p>
|
||||
(C) Copyright Neil Groves 2009
|
||||
(C) Copyright Thorsten Ottosen 2003-2004
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
</body>
|
||||
</html>
|
||||
|
45
doc/reference/adaptors/sliced.qbk
Normal file
45
doc/reference/adaptors/sliced.qbk
Normal file
@ -0,0 +1,45 @@
|
||||
[section:sliced sliced]
|
||||
|
||||
[table
|
||||
[[Syntax] [Code]]
|
||||
[[Pipe] [`rng | boost::adaptors::sliced(n, m)`]]
|
||||
[[Function] [`boost::adaptors::slice(rng, n, m)`]]
|
||||
]
|
||||
|
||||
* [*Precondition:] `0 <= n && n <= m && m < distance(rng)`
|
||||
* [*Returns:] `make_range(rng, n, m)`
|
||||
* [*Range Category:] `RandomAccessRange`
|
||||
|
||||
[section:sliced_example sliced example]
|
||||
``
|
||||
#include <boost/range/adaptor/sliced.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;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
boost::copy(
|
||||
input | sliced(2, 5),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
``
|
||||
[endsect]
|
||||
|
||||
This would produce the output:
|
||||
``
|
||||
3,4,5
|
||||
``
|
||||
[endsect]
|
||||
|
||||
|
94
doc/reference/adaptors/strided.html
Executable file
94
doc/reference/adaptors/strided.html
Executable file
@ -0,0 +1,94 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Boost.Range Range Adaptors </title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<table border="0" >
|
||||
<tr>
|
||||
<td ><img src="../../../boost.png" border="0" /></td>
|
||||
<td ><h1 align="center">Boost.Range </h1></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2> Range Adaptors </h2>
|
||||
|
||||
<hr />
|
||||
<a name="strided"></a>
|
||||
<h4><code>strided</code></h4>
|
||||
<blockquote>
|
||||
<pre>rng | boost::adaptors::strided( n )</pre>
|
||||
<pre>boost::make_strided_range( rng, n )</pre>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Precondition:</b>
|
||||
<code>0 <= n && n <= distance(rng)</code>
|
||||
</li>
|
||||
<li>
|
||||
<b>Returns:</b>
|
||||
A new range based on <code>rng</code> where traversal is performed in steps of <code>n</code>.
|
||||
</li>
|
||||
<li>
|
||||
<b>Range Category:</b>
|
||||
RandomAccessRange
|
||||
</li>
|
||||
</ul>
|
||||
<hr />
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
<span class="keyword">#include</span> <boost/range/adaptor/strided.hpp>
|
||||
<span class="keyword">#include</span> <boost/range/algorithm/copy.hpp>
|
||||
<span class="keyword">#include</span> <boost/assign.hpp>
|
||||
<span class="keyword">#include</span> <algorithm>
|
||||
<span class="keyword">#include</span> <iostream>
|
||||
<span class="keyword">#include</span> <vector>
|
||||
|
||||
<span class="keyword">int</span> main(<span class="keyword">int</span> argc, <span class="keyword">const char</span>* argv[])
|
||||
{
|
||||
<span class="keyword">using namespace</span> boost::adaptors;
|
||||
<span class="keyword">using namespace</span> boost::assign;
|
||||
|
||||
std::vector<<span class="keyword">int</span>> input;
|
||||
input += 1,2,3,4,5,6,7,8,9,10;
|
||||
|
||||
boost::copy(
|
||||
input | strided(2),
|
||||
std::ostream_iterator<<span class="keyword">int</span>>(std::cout, ","));
|
||||
|
||||
<span class="keyword">return</span> 0;
|
||||
}
|
||||
</pre>
|
||||
<p>
|
||||
This produces the output:
|
||||
<code>
|
||||
1,3,5,7,9
|
||||
</code>
|
||||
</p>
|
||||
|
||||
<hr />
|
||||
<p>
|
||||
(C) Copyright Neil Groves 2009
|
||||
(C) Copyright Thorsten Ottosen 2003-2004
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
</body>
|
||||
</html>
|
||||
|
45
doc/reference/adaptors/strided.qbk
Normal file
45
doc/reference/adaptors/strided.qbk
Normal file
@ -0,0 +1,45 @@
|
||||
[section:strided strided]
|
||||
|
||||
[table
|
||||
[[Syntax] [Code]]
|
||||
[[Pipe] [`rng | boost::adaptors::strided(n)`]]
|
||||
[[Function] [`boost::adaptors::stride(rng, n)`]]
|
||||
]
|
||||
|
||||
* [*Precondition:] `0 <= n && n < distance(rng)`
|
||||
* [*Returns:] A new range based on `rng` where traversal is performed in steps of `n`.
|
||||
* [*Range Category:] `RandomAccessRange`
|
||||
|
||||
[section:strided_example strided example]
|
||||
``
|
||||
#include <boost/range/adaptor/strided.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;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9,10;
|
||||
|
||||
boost::copy(
|
||||
input | strided(2),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
``
|
||||
[endsect]
|
||||
|
||||
This would produce the output:
|
||||
``
|
||||
1,3,5,7,9
|
||||
``
|
||||
[endsect]
|
||||
|
||||
|
118
doc/reference/adaptors/tokenized.html
Executable file
118
doc/reference/adaptors/tokenized.html
Executable file
@ -0,0 +1,118 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Boost.Range Range Adaptors </title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<table border="0" >
|
||||
<tr>
|
||||
<td ><img src="../../../boost.png" border="0" /></td>
|
||||
<td ><h1 align="center">Boost.Range </h1></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2> Range Adaptors </h2>
|
||||
|
||||
<hr />
|
||||
<a name="tokenized"></a>
|
||||
<h4><code>tokenized</code></h4>
|
||||
<blockquote>
|
||||
<pre>rng | boost::adaptors::tokenized( regex )</pre>
|
||||
<pre>rng | boost::adaptors::tokenized( regex, i )</pre>
|
||||
<pre>rng | boost::adaptors::tokenized( regex, rndRng )</pre>
|
||||
<pre>rng | boost::adaptors::tokenized( regex, i, flags )</pre>
|
||||
<pre>rng | boost::adaptors::tokenized( regex, rndRng, flags )</pre>
|
||||
<pre>boost::make_tokenized_range( rng, regex, i, flags )</pre>
|
||||
<pre>boost::make_tokenized_range( rng, regex, rngRng, flags )</pre>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Precondition:</b>
|
||||
<ul>
|
||||
<li>
|
||||
Let <code>T</code> denote
|
||||
<code>typename range_value< decltype(rng) >::type</code>,
|
||||
then <code>regex</code> has the type
|
||||
<code>basic_regex<T></code> or is
|
||||
implicitly convertible to one of these types.
|
||||
</li>
|
||||
<li>
|
||||
<code>i</code> has the type <code>int</code>.
|
||||
</li>
|
||||
<li>
|
||||
the value-type of <code>rndRng</code> is <code>int</code>.
|
||||
</li>
|
||||
<li>
|
||||
<code>flags</code> has the type
|
||||
<code>regex_constants::syntax_option_type</code>.
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<b>Returns:</b>
|
||||
A range whose iterators behave as if they were the
|
||||
original iterators wrapped in <code>regex_token_iterator</code>.
|
||||
The first iterator in the range would be constructed by
|
||||
forwarding all the arguments of <code>tokenized()</code> to the
|
||||
<code>regex_token_iterator</code> constructor.
|
||||
</li>
|
||||
<li>
|
||||
<b>Throws:</b>
|
||||
Whatever constructing and copying equivalent
|
||||
<code>regex_token_iterator</code>s might throw.
|
||||
</li>
|
||||
<li>
|
||||
<b>Range Category:</b>
|
||||
RandomAccessRange
|
||||
</li>
|
||||
</ul>
|
||||
<hr />
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
<span class="keyword">#include</span> <boost/range/adaptor/tokenized.hpp>
|
||||
<span class="keyword">#include</span> <boost/range/algorithm_ext/push_back.hpp>
|
||||
<span class="keyword">#include</span> <boost/assert.hpp>
|
||||
<span class="keyword">#include</span> <algorithm>
|
||||
<span class="keyword">#include</span> <string>
|
||||
<span class="keyword">#include</span> <vector>
|
||||
|
||||
<span class="keyword">int</span> main(<span class="keyword">int</span> argc, <span class="keyword">const char</span>* argv)
|
||||
{
|
||||
<span class="keyword">using namespace</span> 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 );
|
||||
|
||||
<span class="keyword">return</span> 0;
|
||||
}
|
||||
</pre>
|
||||
|
||||
<hr />
|
||||
<p>
|
||||
(C) Copyright Neil Groves 2009
|
||||
(C) Copyright Thorsten Ottosen 2003-2004
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
</body>
|
||||
</html>
|
||||
|
42
doc/reference/adaptors/tokenized.qbk
Normal file
42
doc/reference/adaptors/tokenized.qbk
Normal file
@ -0,0 +1,42 @@
|
||||
[section:tokenized tokenized]
|
||||
|
||||
[table
|
||||
[[Syntax] [Code]]
|
||||
[
|
||||
[Pipe]
|
||||
[
|
||||
``
|
||||
rng | boost::adaptors::tokenized(regex)
|
||||
rng | boost::adaptors::tokenized(regex, i)
|
||||
rng | boost::adaptors::tokenized(regex, rndRng)
|
||||
rng | boost::adaptors::tokenized(regex, i, flags)
|
||||
rng | boost::adaptors::tokenized(regex, rndRng, flags)
|
||||
``
|
||||
]
|
||||
]
|
||||
[
|
||||
[Function]
|
||||
[
|
||||
``
|
||||
boost::adaptors::tokenize(rng, regex)
|
||||
boost::adaptors::tokenize(rng, regex, i)
|
||||
boost::adaptors::tokenize(rng, regex, rndRng)
|
||||
boost::adaptors::tokenize(rng, regex, i, flags)
|
||||
boost::adaptors::tokenize(rng, regex, rndRng, flags)
|
||||
``
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
* [*Precondition:]
|
||||
* Let `T` denote `typename range_value<decltype(rng)>::type`, then `regex` has the type `basic_regex<T>` or is implicitly convertible to one of these types.
|
||||
* `i` has the type `int`.
|
||||
* the `value_type` of `rndRng` is `int`.
|
||||
* `flags` has the type `regex_constants::syntax_option_type`.
|
||||
* [*Returns:] A range whose iterators behave as if they were the original iterators wrapped in `regex_token_iterator`. The first iterator in the range would be constructed by forwarding all the arguments of `tokenized()` to the `regex_token_iterator` constructor.
|
||||
* [*Throws:] Whatever constructing and copying equivalent `regex_token_iterator`s might throw.
|
||||
* [*Range Category:] `RandomAccessRange`
|
||||
|
||||
[endsect]
|
||||
|
||||
|
107
doc/reference/adaptors/transformed.html
Executable file
107
doc/reference/adaptors/transformed.html
Executable file
@ -0,0 +1,107 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Boost.Range Range Adaptors </title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<table border="0" >
|
||||
<tr>
|
||||
<td ><img src="../../../boost.png" border="0" /></td>
|
||||
<td ><h1 align="center">Boost.Range </h1></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2> Range Adaptors </h2>
|
||||
|
||||
<hr />
|
||||
<a name="transformed"></a>
|
||||
<h4><code>transformed</code></h4>
|
||||
<blockquote>
|
||||
<pre>rng | boost::adaptors::transformed( fun )</pre>
|
||||
<pre>boost::make_transformed_range( rng, fun )</pre>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Precondition:</b>
|
||||
The value-type of the range is convertible to the argument type
|
||||
of fun.
|
||||
</li>
|
||||
<li>
|
||||
<b>Postcondition:</b>
|
||||
For all elements <code>x</code> in the returned range,
|
||||
<code>x</code> is the result of <code>fun(y)</code> where
|
||||
<code>y</code> is the corresponding element in the original range.
|
||||
</li>
|
||||
<li>
|
||||
<b>Throws:</b>
|
||||
Whatever the copy-constructor of <code>fun</code> might throw.
|
||||
</li>
|
||||
<li>
|
||||
<b>Range Category:</b>
|
||||
SinglePassRange
|
||||
</li>
|
||||
</ul>
|
||||
<hr />
|
||||
<h3>Example</h3>
|
||||
<pre>
|
||||
<span class="keyword">#include</span> <boost/range/adaptor/transformed.hpp>
|
||||
<span class="keyword">#include</span> <boost/range/algorithm/copy.hpp>
|
||||
<span class="keyword">#include</span> <boost/range/assign.hpp>
|
||||
<span class="keyword">#include</span> <algorithm>
|
||||
<span class="keyword">#include</span> <iostream>
|
||||
<span class="keyword">#include</span> <vector>
|
||||
|
||||
<span class="keyword">struct</span> double_int
|
||||
{
|
||||
<span class="keyword">typedef int</span> result_type;
|
||||
<span class="keyword">int operator</span>()(<span class="keyword">int</span> x) <span class="keyword">const</span> { <span class="keyword">return</span> x * 2; }
|
||||
};
|
||||
|
||||
<span class="keyword">int</span> main(<span class="keyword">int</span> argc, <span class="keyword">const char</span>* argv[])
|
||||
{
|
||||
<span class="keyword">using namespace</span> boost::adaptors;
|
||||
<span class="keyword">using namespace</span> boost::assign;
|
||||
|
||||
std::vector<<span class="keyword">int</span>> input;
|
||||
input += 1,2,3,4,5,6,7,8,9,10;
|
||||
|
||||
boost::copy(
|
||||
input | transformed(double_int()),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
<span class="keyword">return</span> 0;
|
||||
}
|
||||
</pre>
|
||||
<p>
|
||||
This produces the output: <br />
|
||||
<code>
|
||||
2,4,6,8,10,12,14,16,18,20
|
||||
</code>
|
||||
</p>
|
||||
|
||||
<hr />
|
||||
<p>
|
||||
(C) Copyright Neil Groves 2009
|
||||
(C) Copyright Thorsten Ottosen 2003-2004
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
</body>
|
||||
</html>
|
||||
|
52
doc/reference/adaptors/transformed.qbk
Normal file
52
doc/reference/adaptors/transformed.qbk
Normal file
@ -0,0 +1,52 @@
|
||||
[section:transformed transformed]
|
||||
|
||||
[table
|
||||
[[Syntax] [Code]]
|
||||
[[Pipe] [`rng | boost::adaptors::transformed(fun)`]]
|
||||
[[Function] [`boost::adaptors::transform(rng, fun)`]]
|
||||
]
|
||||
|
||||
* [*Precondition:] The `value_type` of the range is convertible to the argument type of `fun`.
|
||||
* [*Postcondition:] For all elements `x` in the returned range, `x` is the result of `fun(y)` where `y` is the corresponding element in the original range.
|
||||
* [*Throws:] Whatever the copy-constructor of `fun` might throw.
|
||||
* [*Range Category:] `SinglePassRange`
|
||||
|
||||
[section:transformed_example transformed example]
|
||||
``
|
||||
#include <boost/range/adaptor/transformed.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
struct double_int
|
||||
{
|
||||
typedef int result_type;
|
||||
int operator()(int x) const { return x * 2; }
|
||||
};
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9,10;
|
||||
|
||||
boost::copy(
|
||||
input | transformed(double_int()),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
return 0;
|
||||
}
|
||||
``
|
||||
[endsect]
|
||||
|
||||
This would produce the output:
|
||||
``
|
||||
2,4,6,8,10,12,14,16,18,20
|
||||
``
|
||||
[endsect]
|
||||
|
||||
|
95
doc/reference/adaptors/uniqued.html
Executable file
95
doc/reference/adaptors/uniqued.html
Executable file
@ -0,0 +1,95 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Boost.Range Range Adaptors </title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<table border="0" >
|
||||
<tr>
|
||||
<td ><img src="../../../boost.png" border="0" /></td>
|
||||
<td ><h1 align="center">Boost.Range </h1></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2> Range Adaptors </h2>
|
||||
|
||||
<hr />
|
||||
<a name="uniqued"></a>
|
||||
<h4><code>uniqued</code></h4>
|
||||
<blockquote>
|
||||
<pre>rng | boost::adaptors::uniqued</pre>
|
||||
<pre>boost::make_uniqued_range( rng )</pre>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li>
|
||||
<b>Precondition:</b>
|
||||
The value-type of the range is comparable with
|
||||
<code>operator==()</code>.
|
||||
</li>
|
||||
<li>
|
||||
<b>Postcondition:</b>
|
||||
For all adjacent elements <code>[x,y]</code> in the returned range,
|
||||
<code>x==y</code> is false.
|
||||
</li>
|
||||
<li>
|
||||
<b>Range Category:</b>
|
||||
ForwardRange
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<hr />
|
||||
<h3>Example</h3>
|
||||
|
||||
<pre>
|
||||
#include <boost/range/adaptor/uniqued.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::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,1,2,2,2,3,4,5,6;
|
||||
|
||||
boost::copy(
|
||||
input | uniqued,
|
||||
std::ostream_iterator<int>(std::cout, ",") );
|
||||
|
||||
return 0;
|
||||
}
|
||||
</pre>
|
||||
<p>
|
||||
This would produce the output:<br />
|
||||
<code>1,2,3,4,5,6</code><br />
|
||||
</p>
|
||||
<hr />
|
||||
<p>
|
||||
(C) Copyright Neil Groves 2009
|
||||
(C) Copyright Thorsten Ottosen 2003-2004
|
||||
</p>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
</body>
|
||||
</html>
|
||||
|
43
doc/reference/adaptors/uniqued.qbk
Normal file
43
doc/reference/adaptors/uniqued.qbk
Normal file
@ -0,0 +1,43 @@
|
||||
[section:uniqued uniqued]
|
||||
|
||||
[table
|
||||
[[Syntax] [Code]]
|
||||
[[Pipe] [`rng | boost::adaptors::uniqued`]]
|
||||
[[Function] [`boost::adaptors::unique(rng)`]]
|
||||
]
|
||||
|
||||
* [*Precondition:] The `value_type` of the range is comparable with `operator==()`.
|
||||
* [*Postcondition:] For all adjacent elements `[x,y]` in the returned range, `x==y` is false.
|
||||
* [*Range Category:] `ForwardRange`
|
||||
|
||||
[section:uniqued_example uniqued example]
|
||||
``
|
||||
#include <boost/range/adaptor/uniqued.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
void uniqued_example_test()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,1,2,2,2,3,4,5,6;
|
||||
|
||||
boost::copy(
|
||||
input | uniqued,
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
}
|
||||
``
|
||||
[endsect]
|
||||
|
||||
This would produce the output:
|
||||
``
|
||||
1,2,3,4,5,6
|
||||
``
|
||||
[endsect]
|
||||
|
||||
|
Reference in New Issue
Block a user