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:
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user