@@ -13,87 +13,96 @@ using iter::dropwhile;
1313using Vec = const std::vector<int >;
1414
1515TEST_CASE (" dropwhile: skips initial elements" , " [dropwhile]" ) {
16- Vec ns{1 ,2 , 3 , 4 , 5 , 6 , 7 , 8 };
17- auto d = dropwhile ([](int i){ return i < 5 ; }, ns);
18- Vec v (std::begin (d), std::end (d));
19- Vec vc = {5 ,6 , 7 , 8 };
20- REQUIRE ( v == vc );
16+ Vec ns{1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
17+ auto d = dropwhile ([](int i) { return i < 5 ; }, ns);
18+ Vec v (std::begin (d), std::end (d));
19+ Vec vc = {5 , 6 , 7 , 8 };
20+ REQUIRE (v == vc);
2121}
2222
2323TEST_CASE (" dropwhile: doesn't skip anything if it shouldn't" , " [dropwhile]" ) {
24- Vec ns {3 ,4 , 5 , 6 };
25- auto d = dropwhile ([](int i){ return i < 3 ; }, ns);
26- Vec v (std::begin (d), std::end (d));
27- Vec vc = {3 ,4 , 5 , 6 };
28- REQUIRE ( v == vc );
24+ Vec ns{3 , 4 , 5 , 6 };
25+ auto d = dropwhile ([](int i) { return i < 3 ; }, ns);
26+ Vec v (std::begin (d), std::end (d));
27+ Vec vc = {3 , 4 , 5 , 6 };
28+ REQUIRE (v == vc);
2929}
3030
3131TEST_CASE (" dropwhile: skips all elements when all are true under predicate" ,
32- " [dropwhile]" ) {
33- Vec ns {3 ,4 , 5 , 6 };
34- auto d = dropwhile ([](int i){ return i != 0 ; }, ns);
35- REQUIRE ( std::begin (d) == std::end (d) );
32+ " [dropwhile]" ) {
33+ Vec ns{3 , 4 , 5 , 6 };
34+ auto d = dropwhile ([](int i) { return i != 0 ; }, ns);
35+ REQUIRE (std::begin (d) == std::end (d));
3636}
3737
3838TEST_CASE (" dropwhile: empty case is empty" , " [dropwhile]" ) {
39- Vec ns{};
40- auto d = dropwhile ([](int i){ return i != 0 ; }, ns);
41- REQUIRE ( std::begin (d) == std::end (d) );
39+ Vec ns{};
40+ auto d = dropwhile ([](int i) { return i != 0 ; }, ns);
41+ REQUIRE (std::begin (d) == std::end (d));
4242}
4343
4444TEST_CASE (" dropwhile: only drops from beginning" , " [dropwhile]" ) {
45- Vec ns {1 ,2 , 3 , 4 , 5 , 6 , 5 , 4 , 3 , 2 , 1 };
46- auto d = dropwhile ([](int i){ return i < 5 ; }, ns);
47- Vec v (std::begin (d), std::end (d));
48- Vec vc = {5 ,6 , 5 , 4 , 3 , 2 , 1 };
49- REQUIRE ( v == vc );
45+ Vec ns{1 , 2 , 3 , 4 , 5 , 6 , 5 , 4 , 3 , 2 , 1 };
46+ auto d = dropwhile ([](int i) { return i < 5 ; }, ns);
47+ Vec v (std::begin (d), std::end (d));
48+ Vec vc = {5 , 6 , 5 , 4 , 3 , 2 , 1 };
49+ REQUIRE (v == vc);
5050}
5151
5252TEST_CASE (" dropwhile: operator->" , " [dropwhile]" ) {
53- std::vector<std::string> vs = {" a" , " ab" , " abcdef" , " abcdefghi" };
54- auto d = dropwhile (
55- [](const std::string& str) { return str.size () < 3 ; }, vs);
56- auto it = std::begin (d);
57- REQUIRE ( it->size () == 6 );
53+ std::vector<std::string> vs = {" a" , " ab" , " abcdef" , " abcdefghi" };
54+ auto d = dropwhile ([](const std::string& str) { return str.size () < 3 ; }, vs);
55+ auto it = std::begin (d);
56+ REQUIRE (it->size () == 6 );
5857}
5958
6059namespace {
61- int less_than_five (int i) {
62- return i < 5 ;
63- }
60+ int less_than_five (int i) {
61+ return i < 5 ;
62+ }
6463}
6564
6665TEST_CASE (" dropwhile: works with function pointer" , " [dropwhile]" ) {
67- Vec ns{1 ,2 , 3 , 4 , 5 , 6 , 7 , 8 };
68- auto d = dropwhile (less_than_five, ns);
69- Vec v (std::begin (d), std::end (d));
70- Vec vc = {5 ,6 , 7 , 8 };
71- REQUIRE ( v == vc );
66+ Vec ns{1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
67+ auto d = dropwhile (less_than_five, ns);
68+ Vec v (std::begin (d), std::end (d));
69+ Vec vc = {5 , 6 , 7 , 8 };
70+ REQUIRE (v == vc);
7271}
7372
7473TEST_CASE (" dropwhile: binds to lvalues, moves rvalues" , " [dropwhile]" ) {
75- itertest::BasicIterable<int > bi{1 ,2 , 3 , 4 };
76- SECTION (" binds to lvalues" ) {
77- dropwhile (less_than_five, bi);
78- REQUIRE_FALSE ( bi.was_moved_from () );
79- }
80- SECTION (" moves rvalues" ) {
81- dropwhile (less_than_five, std::move (bi));
82- REQUIRE ( bi.was_moved_from () );
83- }
74+ itertest::BasicIterable<int > bi{1 , 2 , 3 , 4 };
75+ SECTION (" binds to lvalues" ) {
76+ dropwhile (less_than_five, bi);
77+ REQUIRE_FALSE (bi.was_moved_from ());
78+ }
79+ SECTION (" moves rvalues" ) {
80+ dropwhile (less_than_five, std::move (bi));
81+ REQUIRE (bi.was_moved_from ());
82+ }
8483}
8584
86- TEST_CASE (" dropwhile: doesn't move or copy elements of iterable " ,
87- " [dropwhile]" ) {
88- constexpr itertest::SolidInt arr[] = {{6 }, {7 }, {8 }};
89- for (auto && i : dropwhile (
90- [](const itertest::SolidInt&){ return false ;} , arr)) {
91- (void )i;
92- }
85+ TEST_CASE (
86+ " dropwhile: doesn't move or copy elements of iterable " , " [dropwhile]" ) {
87+ constexpr itertest::SolidInt arr[] = {{6 }, {7 }, {8 }};
88+ for (auto && i :
89+ dropwhile ( [](const itertest::SolidInt&) { return false ; } , arr)) {
90+ (void )i;
91+ }
9392}
9493
9594TEST_CASE (" dropwhile: iterator meets requirements" , " [dropwhile]" ) {
96- std::string s{};
97- auto c = dropwhile ([]{return true ;}, s);
98- REQUIRE ( itertest::IsIterator<decltype (std::begin (c))>::value );
95+ std::string s{};
96+ auto c = dropwhile ([] { return true ; }, s);
97+ REQUIRE (itertest::IsIterator<decltype (std::begin (c))>::value);
98+ }
99+
100+ template <typename T, typename U>
101+ using ImpT = decltype (dropwhile(std::declval<T>(), std::declval<U>()));
102+ TEST_CASE (" dropwhile: has correct ctor and assign ops" , " [dropwhile]" ) {
103+ using T1 = ImpT<bool (*)(char c), std::string&>;
104+ auto lam = [](char ) { return false ; };
105+ using T2 = ImpT<decltype (lam), std::string>;
106+ REQUIRE (itertest::IsMoveConstructibleOnly<T1>::value);
107+ REQUIRE (itertest::IsMoveConstructibleOnly<T2>::value);
99108}
0 commit comments