@@ -17,93 +17,100 @@ using itertest::BasicIterable;
1717using itertest::SolidInt;
1818
1919TEST_CASE (" zip: Simple case, same length" , " [zip]" ) {
20- using Tu = std::tuple<int , char , double >;
21- using ResVec = const std::vector<Tu>;
22- std::vector<int > iv {10 , 20 , 30 };
23- std::string s{" hey" };
24- double arr[] = {1.0 , 2.0 , 4.0 };
25-
26- auto z = zip (iv, s, arr);
27- ResVec v (std::begin (z), std::end (z));
28- ResVec vc {Tu{10 , ' h' , 1.0 }, Tu{20 , ' e' , 2.0 }, Tu{30 , ' y' , 4.0 }};
29- REQUIRE ( v == vc );
20+ using Tu = std::tuple<int , char , double >;
21+ using ResVec = const std::vector<Tu>;
22+ std::vector<int > iv{10 , 20 , 30 };
23+ std::string s{" hey" };
24+ double arr[] = {1.0 , 2.0 , 4.0 };
25+
26+ auto z = zip (iv, s, arr);
27+ ResVec v (std::begin (z), std::end (z));
28+ ResVec vc{Tu{10 , ' h' , 1.0 }, Tu{20 , ' e' , 2.0 }, Tu{30 , ' y' , 4.0 }};
29+ REQUIRE (v == vc);
3030}
3131
3232TEST_CASE (" zip: One empty, all empty" , " [zip]" ) {
33- std::vector<int > iv = {1 ,2 , 3 };
34- std::string s{};
35- auto z = zip (iv, s);
36- REQUIRE_FALSE ( std::begin (z) != std::end (z) );
37- auto z2 = zip (s, iv);
38- REQUIRE_FALSE ( std::begin (z2) != std::end (z2) );
33+ std::vector<int > iv = {1 , 2 , 3 };
34+ std::string s{};
35+ auto z = zip (iv, s);
36+ REQUIRE_FALSE (std::begin (z) != std::end (z));
37+ auto z2 = zip (s, iv);
38+ REQUIRE_FALSE (std::begin (z2) != std::end (z2));
3939}
4040
4141TEST_CASE (" zip: terminates on shortest sequence" , " [zip]" ) {
42- std::vector<int > iv{1 ,2 , 3 , 4 , 5 };
43- std::string s{" hi" };
44- auto z = zip (iv, s);
42+ std::vector<int > iv{1 , 2 , 3 , 4 , 5 };
43+ std::string s{" hi" };
44+ auto z = zip (iv, s);
4545
46- REQUIRE ( std::distance (std::begin (z), std::end (z)) == 2 );
46+ REQUIRE (std::distance (std::begin (z), std::end (z)) == 2 );
4747}
4848
4949TEST_CASE (" zip: Empty" , " [zip]" ) {
50- auto z = zip ();
51- REQUIRE_FALSE ( std::begin (z) != std::end (z) );
50+ auto z = zip ();
51+ REQUIRE_FALSE (std::begin (z) != std::end (z));
5252}
5353
5454TEST_CASE (" zip: Modify sequence through zip" , " [zip]" ) {
55- std::vector<int > iv{1 ,2 , 3 };
56- std::vector<int > iv2{1 ,2 , 3 , 4 };
57- for (auto && t : zip (iv, iv2)) {
58- std::get<0 >(t) = -1 ;
59- std::get<1 >(t) = -1 ;
60- }
61-
62- const std::vector<int > vc{-1 , -1 , -1 };
63- const std::vector<int > vc2{-1 , -1 , -1 , 4 };
64- REQUIRE ( iv == vc);
65- REQUIRE ( iv2 == vc2);
55+ std::vector<int > iv{1 , 2 , 3 };
56+ std::vector<int > iv2{1 , 2 , 3 , 4 };
57+ for (auto && t : zip (iv, iv2)) {
58+ std::get<0 >(t) = -1 ;
59+ std::get<1 >(t) = -1 ;
60+ }
61+
62+ const std::vector<int > vc{-1 , -1 , -1 };
63+ const std::vector<int > vc2{-1 , -1 , -1 , 4 };
64+ REQUIRE (iv == vc);
65+ REQUIRE (iv2 == vc2);
6666}
6767
6868TEST_CASE (" zip: binds reference when it should" , " [zip]" ) {
69- BasicIterable<char > bi{' x' , ' y' , ' z' };
70- zip (bi);
71- REQUIRE_FALSE ( bi.was_moved_from () );
69+ BasicIterable<char > bi{' x' , ' y' , ' z' };
70+ zip (bi);
71+ REQUIRE_FALSE (bi.was_moved_from ());
7272}
7373
7474TEST_CASE (" zip: moves rvalues" , " [zip]" ) {
75- BasicIterable<char > bi{' x' , ' y' , ' z' };
76- zip (std::move (bi));
77- REQUIRE ( bi.was_moved_from () );
75+ BasicIterable<char > bi{' x' , ' y' , ' z' };
76+ zip (std::move (bi));
77+ REQUIRE (bi.was_moved_from ());
7878}
7979
8080TEST_CASE (" zip: Can bind ref and move in single zip" , " [zip]" ) {
81- BasicIterable<char > b1{' x' , ' y' , ' z' };
82- BasicIterable<char > b2{' a' , ' b' };
83- zip (b1, std::move (b2));
84- REQUIRE_FALSE ( b1.was_moved_from () );
85- REQUIRE ( b2.was_moved_from () );
81+ BasicIterable<char > b1{' x' , ' y' , ' z' };
82+ BasicIterable<char > b2{' a' , ' b' };
83+ zip (b1, std::move (b2));
84+ REQUIRE_FALSE (b1.was_moved_from ());
85+ REQUIRE (b2.was_moved_from ());
8686}
8787
8888TEST_CASE (" zip: doesn't move or copy elements of iterable" , " [zip]" ) {
89- constexpr SolidInt arr[] = {{6 }, {7 }, {8 }};
90- for (auto && t : zip (arr)) {
91- (void )std::get<0 >(t);
92- }
89+ constexpr SolidInt arr[] = {{6 }, {7 }, {8 }};
90+ for (auto && t : zip (arr)) {
91+ (void )std::get<0 >(t);
92+ }
9393}
9494
9595TEST_CASE (" zip: postfix ++" , " [zip]" ) {
96- const std::vector<int > v = {1 };
97- auto z = zip (v);
98- auto it = std::begin (z);
99- it++;
100- REQUIRE ( it == std::end (z) );
96+ const std::vector<int > v = {1 };
97+ auto z = zip (v);
98+ auto it = std::begin (z);
99+ it++;
100+ REQUIRE (it == std::end (z));
101101}
102102
103103TEST_CASE (" zip: iterator meets requirements" , " [zip]" ) {
104- std::string s{};
105- auto c = zip (s);
106- REQUIRE ( itertest::IsIterator<decltype (std::begin (c))>::value );
107- auto c2 = zip (s, s);
108- REQUIRE ( itertest::IsIterator<decltype (std::begin (c2))>::value );
104+ std::string s{};
105+ auto c = zip (s);
106+ REQUIRE (itertest::IsIterator<decltype (std::begin (c))>::value);
107+ auto c2 = zip (s, s);
108+ REQUIRE (itertest::IsIterator<decltype (std::begin (c2))>::value);
109+ }
110+
111+ template <typename ... Ts>
112+ using ImpT = decltype (zip(std::declval<Ts>()...));
113+ TEST_CASE (" zip: has correct ctor and assign ops" , " [zip]" ) {
114+ using T = ImpT<std::string&, std::vector<double >, std::vector<std::string>>;
115+ REQUIRE (itertest::IsMoveConstructibleOnly<T>::value);
109116}
0 commit comments