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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
// Boost.Range library
//
// Copyright Neil Groves 2014
//
// Copyright Thorsten Ottosen 2006. 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)
//
// For more information, see http://www.boost.org/libs/range/
//
#include <boost/range/combine.hpp>
#include <boost/range/algorithm_ext/push_back.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/foreach.hpp>
#include <vector>
namespace boost_range_test
{
namespace
{
template<typename ContRef1, typename ContRef2>
void test_combine2()
{
std::vector<int> v;
std::list<int> l;
for (int i = 0; i < 10; ++i)
{
v.push_back(i);
l.push_back(i * 2);
}
ContRef1& in1 = v;
ContRef2& in2 = l;
std::vector<boost::tuple<int,int> > output;
boost::push_back(output, boost::combine(in1, in2));
int index = 0;
int i1, i2;
BOOST_FOREACH(boost::tie(i1,i2), output)
{
BOOST_CHECK_EQUAL(i1, index);
BOOST_CHECK_EQUAL(i2, index * 2);
++index;
}
}
template<typename ContRef1, typename ContRef2, typename ContRef3>
void test_combine3()
{
std::vector<int> v1;
std::vector<int> v2;
std::vector<int> v3;
for (int i = 0; i < 10; ++i)
{
v1.push_back(i);
v2.push_back(i * 2);
v3.push_back(i * 3);
}
ContRef1& in1 = v1;
ContRef2& in2 = v2;
ContRef3& in3 = v3;
std::vector<boost::tuple<int,int,int> > output;
boost::push_back(output, boost::combine(in1, in2, in3));
int index = 0;
int i1, i2, i3;
BOOST_FOREACH(boost::tie(i1,i2,i3), output)
{
BOOST_CHECK_EQUAL(i1, index);
BOOST_CHECK_EQUAL(i2, index * 2);
BOOST_CHECK_EQUAL(i3, index * 3);
++index;
}
}
} // anonymous namespace
} // namespace boost_range_test
boost::unit_test::test_suite* init_unit_test_suite(int, char*[] )
{
boost::unit_test::test_suite* test =
BOOST_TEST_SUITE( "Boost.Range combine() test suite" );
test->add(BOOST_TEST_CASE((
&boost_range_test::test_combine2<
const std::vector<int>, const std::list<int> >)));
test->add(BOOST_TEST_CASE((
&boost_range_test::test_combine2<
const std::vector<int>, std::list<int> >)));
test->add(BOOST_TEST_CASE((
&boost_range_test::test_combine2<
std::vector<int>, const std::list<int> >)));
test->add(BOOST_TEST_CASE((
&boost_range_test::test_combine2<
std::vector<int>, std::list<int> >)));
test->add(BOOST_TEST_CASE((
&boost_range_test::test_combine3<
std::vector<int>,
std::vector<int>,
std::vector<int> >)));
test->add(BOOST_TEST_CASE((
&boost_range_test::test_combine3<
std::vector<int>,
std::vector<int>,
const std::vector<int> >)));
test->add(BOOST_TEST_CASE((
&boost_range_test::test_combine3<
std::vector<int>,
const std::vector<int>,
std::vector<int> >)));
test->add(BOOST_TEST_CASE((
&boost_range_test::test_combine3<
std::vector<int>,
const std::vector<int>,
const std::vector<int> >)));
test->add(BOOST_TEST_CASE((
&boost_range_test::test_combine3<
const std::vector<int>,
std::vector<int>,
std::vector<int> >)));
test->add(BOOST_TEST_CASE((
&boost_range_test::test_combine3<
const std::vector<int>,
std::vector<int>,
const std::vector<int> >)));
test->add(BOOST_TEST_CASE((
&boost_range_test::test_combine3<
const std::vector<int>,
const std::vector<int>,
std::vector<int> >)));
test->add(BOOST_TEST_CASE((
&boost_range_test::test_combine3<
const std::vector<int>,
const std::vector<int>,
const std::vector<int> >)));
return test;
}
|