]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
1 | /* |
2 | Copyright (c) Alexander Zaitsev <zamazan4ik@gmail.by>, 2017 | |
3 | ||
4 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
5 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | For more information, see http://www.boost.org | |
8 | */ | |
9 | ||
10 | #include <vector> | |
11 | #include <functional> | |
12 | #include <iostream> | |
13 | ||
14 | #include <boost/algorithm/is_partitioned_until.hpp> | |
15 | ||
16 | ||
17 | namespace ba = boost::algorithm; | |
18 | ||
19 | bool isOdd(const int v1) | |
20 | { | |
21 | return v1 % 2 != 0; | |
22 | } | |
23 | ||
24 | struct isOddComp | |
25 | { | |
26 | bool operator()(const int v1) const | |
27 | { | |
28 | return v1 % 2 != 0; | |
29 | } | |
30 | }; | |
31 | ||
32 | ||
33 | int main ( int /*argc*/, char * /*argv*/ [] ) | |
34 | { | |
35 | std::vector<int> good({1, 2, 4}); | |
36 | std::vector<int> bad({1, 2, 3}); | |
37 | ||
38 | //Use custom function | |
39 | auto it1 = ba::is_partitioned_until(good.begin(), good.end(), isOdd); | |
40 | if(it1 == good.end()) | |
41 | { | |
42 | std::cout << "The sequence is partitioned\n"; | |
43 | } | |
44 | else | |
45 | { | |
46 | std::cout << "is_partitioned_until check failed here: " << *it1 << std::endl; | |
47 | } | |
48 | ||
49 | //Use custom comparator | |
50 | auto it2 = ba::is_partitioned_until(good.begin(), good.end(), isOddComp()); | |
51 | if(it2 == good.end()) | |
52 | { | |
53 | std::cout << "The sequence is partitioned\n"; | |
54 | } | |
55 | else | |
56 | { | |
57 | std::cout << "is_partitioned_until check failed here: " << *it2 << std::endl; | |
58 | } | |
59 | ||
60 | auto it3 = ba::is_partitioned_until(bad, isOdd); | |
61 | if(it3 == bad.end()) | |
62 | { | |
63 | std::cout << "The sequence is partitioned\n"; | |
64 | } | |
65 | else | |
66 | { | |
67 | std::cout << "is_partitioned_until check failed here: " << *it3 << std::endl; | |
68 | } | |
69 | return 0; | |
70 | } |