forked from ericniebler/range-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconcat.cpp
More file actions
106 lines (91 loc) · 3.34 KB
/
Copy pathconcat.cpp
File metadata and controls
106 lines (91 loc) · 3.34 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <array>
#include <vector>
#include <range/v3/core.hpp>
#include <range/v3/view/concat.hpp>
#include <range/v3/view/generate.hpp>
#include <range/v3/view/reverse.hpp>
#include <range/v3/view/remove_if.hpp>
#include <range/v3/view/take_while.hpp>
#include <range/v3/algorithm/equal.hpp>
#include <range/v3/utility/copy.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
int main()
{
using namespace ranges;
std::vector<std::string> his_face{"this", "is", "his", "face"};
std::vector<std::string> another_mess{"another", "fine", "mess"};
auto joined = views::concat(his_face, another_mess);
CPP_assert(view_<decltype(joined)>);
CPP_assert(random_access_range<decltype(joined)>);
static_assert(std::is_same<range_reference_t<decltype(joined)>, std::string &>::value, "");
CHECK(joined.size() == 7u);
CHECK((joined.end() - joined.begin()) == 7);
::check_equal(joined | views::reverse, {"mess", "fine", "another", "face", "his", "is", "this"});
auto revjoin = joined | views::reverse;
CHECK((revjoin.end() - revjoin.begin()) == 7);
auto first = joined.begin();
CHECK(*(first+0) == "this");
CHECK(*(first+1) == "is");
CHECK(*(first+2) == "his");
CHECK(*(first+3) == "face");
CHECK(*(first+4) == "another");
CHECK(*(first+5) == "fine");
CHECK(*(first+6) == "mess");
CHECK(*(first) == "this");
CHECK(*(first+=1) == "is");
CHECK(*(first+=1) == "his");
CHECK(*(first+=1) == "face");
CHECK(*(first+=1) == "another");
CHECK(*(first+=1) == "fine");
CHECK(*(first+=1) == "mess");
auto last = joined.end();
CHECK(*(last-1) == "mess");
CHECK(*(last-2) == "fine");
CHECK(*(last-3) == "another");
CHECK(*(last-4) == "face");
CHECK(*(last-5) == "his");
CHECK(*(last-6) == "is");
CHECK(*(last-7) == "this");
CHECK(*(last-=1) == "mess");
CHECK(*(last-=1) == "fine");
CHECK(*(last-=1) == "another");
CHECK(*(last-=1) == "face");
CHECK(*(last-=1) == "his");
CHECK(*(last-=1) == "is");
CHECK(*(last-=1) == "this");
{
const std::array<int, 3> a{{0, 1, 2}};
const std::array<int, 2> b{{3, 4}};
check_equal(views::concat(a, b), {0, 1, 2, 3, 4});
auto odd = [](int i) { return i % 2 != 0; };
auto even_filter = ranges::views::remove_if(odd);
auto f_rng0 = a | even_filter;
auto f_rng1 = b | even_filter;
check_equal(views::concat(f_rng0, f_rng1), {0, 2, 4});
}
// Regression test for http://github.com/ericniebler/range-v3/issues/395.
{
int i = 0;
auto rng = ranges::views::concat(ranges::views::generate([&]{ return i++; }))
| ranges::views::take_while([](int j){ return j < 30; });
CHECK(ranges::distance(ranges::begin(rng), ranges::end(rng)) == 30);
}
{
int const rgi[] = {0,1,2,3};
auto dv = [&]{ return debug_input_view<int const>{rgi}; };
auto rng = views::concat(dv(), dv(), dv());
::check_equal(rng, {0,1,2,3,0,1,2,3,0,1,2,3});
}
return test_result();
}