forked from boostorg/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_1.cpp
More file actions
49 lines (35 loc) · 1.12 KB
/
example_1.cpp
File metadata and controls
49 lines (35 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Boost.Algorithm example
#include <vector>
#include <iostream>
#include <boost/algorithm.hpp>
using namespace boost::algorithm;
using namespace boost::algorithm::sequence;
// Pretty-printer:
template <class T>
void show(std::vector<T>& v);
// Toy function that ignores parameters:
int one_hundred(int&) { return 100; }
int main()
{
int some_numbers[] = { 0, 1, 32, 18, 5 };
std::vector<int> vi(some_numbers, some_numbers + 5);
show(vi);
// none(): See that the values are not all 100:
std::cout << "Are none of the values equal to 100? "
<< ( none(vi, 100) ? "yes" : "no" ) << '\n';
// apply(): Change all the values to 100:
apply(vi, one_hundred);
show(vi);
// all(): See that all of the values are now 100:
std:: cout << "Are any values equal to 100? " <<
( all(vi, 100) ? "yes" : "no" ) << '\n';
}
template <class T>
void show(std::vector<T>& v)
{
for(typename std::vector<T>::const_iterator i = v.begin(); i != v.end(); ++i)
std::cout << *i << '\n';
std::cout << "----------" << std::endl;
}
/// \file example_1.cpp
/// \brief Some examples using the Boost::Algorithm library.