| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <array> | ||
| 2 | #include <vector> | ||
| 3 | #include <string> | ||
| 4 | #include <set> | ||
| 5 | #include <map> | ||
| 6 | #include <list> | ||
| 7 | #include <deque> | ||
| 8 | #include <unordered_set> | ||
| 9 | #include <unordered_map> | ||
| 10 | #include <optional> | ||
| 11 | |||
| 12 | #include "TestCommon.h" | ||
| 13 | |||
| 14 | using namespace CXXIter; | ||
| 15 | |||
| 16 | // ################################################################################################ | ||
| 17 | // CONCEPTS & TYPE CONSTRAINTS & TYPE HELPERS | ||
| 18 | // ################################################################################################ | ||
| 19 | |||
| 20 | 8 | TEST(CXXIter, IterValue) { | |
| 21 | { // Move out of IterValue has to clear source | ||
| 22 | { | ||
| 23 | 2 | IterValue<size_t> src = 1337; | |
| 24 | 2 | IterValue<size_t> dst = std::move(src); | |
| 25 |
2/12✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
2 | ASSERT_FALSE(src.has_value()); |
| 26 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
2 | ASSERT_EQ(dst.value(), 1337); |
| 27 | } | ||
| 28 | { | ||
| 29 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
4 | IterValue<std::string> src = std::string("1337"); |
| 30 | 2 | IterValue<std::string> dst = std::move(src); | |
| 31 |
2/12✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
2 | ASSERT_FALSE(src.has_value()); |
| 32 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
2 | ASSERT_EQ(dst.value(), "1337"); |
| 33 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | } |
| 34 | { | ||
| 35 | 2 | IterValue<size_t> src = 1337; | |
| 36 | 2 | IterValue<size_t> dst(std::move(src)); | |
| 37 |
2/12✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
2 | ASSERT_FALSE(src.has_value()); |
| 38 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
2 | ASSERT_EQ(dst.value(), 1337); |
| 39 | } | ||
| 40 | { | ||
| 41 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
4 | IterValue<std::string> src = std::string("1337"); |
| 42 | 2 | IterValue<std::string> dst(std::move(src)); | |
| 43 |
2/12✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
2 | ASSERT_FALSE(src.has_value()); |
| 44 |
4/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
|
2 | ASSERT_EQ(dst.value(), "1337"); |
| 45 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | } |
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | 8 | TEST(CXXIter, invocable_byvalue) { | |
| 50 | auto fnRValueRef = [](std::string&&) {}; | ||
| 51 | auto fnLValueRef = [](std::string&) {}; | ||
| 52 | auto fnByValue = [](std::string) {}; | ||
| 53 | |||
| 54 | |||
| 55 | static_assert(!CXXIter::util::invocable_byvalue<typeof(fnRValueRef), std::string>); | ||
| 56 | static_assert(!CXXIter::util::invocable_byvalue<typeof(fnLValueRef), std::string>); | ||
| 57 | // should also forbid const lvalue ref - but seems impossible | ||
| 58 | static_assert( CXXIter::util::invocable_byvalue<typeof(fnByValue), std::string>); | ||
| 59 | 2 | } | |
| 60 | |||
| 61 | 8 | TEST(CXXIter, is_const_reference_v) { | |
| 62 | using TestType = std::vector<int>; | ||
| 63 | |||
| 64 |
2/12✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
|
2 | ASSERT_FALSE(CXXIter::util::is_const_reference_v<TestType>); |
| 65 |
2/12✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
|
2 | ASSERT_FALSE(CXXIter::util::is_const_reference_v<TestType&>); |
| 66 |
2/12✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
|
2 | ASSERT_FALSE(CXXIter::util::is_const_reference_v<TestType&&>); |
| 67 | |||
| 68 |
2/12✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
|
2 | ASSERT_TRUE(CXXIter::util::is_const_reference_v<const TestType&>); |
| 69 | } | ||
| 70 | |||
| 71 | 8 | TEST(CXXIter, are_same_v) { | |
| 72 | static_assert( CXXIter::util::are_same_v<int, int, int>); | ||
| 73 | static_assert( CXXIter::util::are_same_v<std::vector<int>, std::vector<int>, std::vector<int>>); | ||
| 74 | static_assert( CXXIter::util::are_same_v<float, float, float>); | ||
| 75 | static_assert( CXXIter::util::are_same_v<std::optional<int>, std::optional<int>, std::optional<int>>); | ||
| 76 | static_assert(!CXXIter::util::are_same_v<int, float, int>); | ||
| 77 | static_assert(!CXXIter::util::are_same_v<std::vector<int>, std::vector<int>, std::vector<float>>); | ||
| 78 | static_assert(!CXXIter::util::are_same_v<float, float, int>); | ||
| 79 | static_assert(!CXXIter::util::are_same_v<std::vector<float>, std::optional<int>, std::optional<int>>); | ||
| 80 | 2 | } | |
| 81 | |||
| 82 | 8 | TEST(CXXIter, CXXIterIterator) { | |
| 83 | using TestSrc = std::vector<int>; | ||
| 84 | |||
| 85 | static_assert( CXXIter::CXXIterIterator< CXXIter::SrcRef<TestSrc> >); | ||
| 86 | static_assert( CXXIter::CXXIterIterator< CXXIter::SrcMov<TestSrc> >); | ||
| 87 | static_assert( CXXIter::CXXIterIterator< CXXIter::SrcCRef<TestSrc> >); | ||
| 88 | static_assert(!CXXIter::CXXIterIterator< std::vector<int> >); | ||
| 89 | static_assert(!CXXIter::CXXIterIterator< std::vector<float> >); | ||
| 90 | static_assert(!CXXIter::CXXIterIterator< std::vector<CXXIter::SrcCRef<TestSrc>> >); | ||
| 91 | static_assert(!CXXIter::CXXIterIterator< int >); | ||
| 92 | static_assert(!CXXIter::CXXIterIterator< void >); | ||
| 93 | 2 | } | |
| 94 | |||
| 95 | 8 | TEST(CXXIter, stlCollections) { | |
| 96 | using TestKey = int; | ||
| 97 | using TestValue = std::string; | ||
| 98 | |||
| 99 | static_assert( CXXIter::util::BackInsertableContainerTemplate<std::vector , TestValue>); | ||
| 100 | static_assert( CXXIter::util::BackInsertableContainerTemplate<std::list , TestValue>); | ||
| 101 | static_assert( CXXIter::util::BackInsertableContainerTemplate<std::deque , TestValue>); | ||
| 102 | static_assert(!CXXIter::util::BackInsertableContainerTemplate<std::set , TestValue>); | ||
| 103 | static_assert(!CXXIter::util::BackInsertableContainerTemplate<std::multiset , TestValue>); | ||
| 104 | static_assert(!CXXIter::util::BackInsertableContainerTemplate<std::unordered_set , TestValue>); | ||
| 105 | static_assert(!CXXIter::util::BackInsertableContainerTemplate<std::unordered_multiset , TestValue>); | ||
| 106 | static_assert(!CXXIter::util::BackInsertableContainerTemplate<std::map , TestValue>); | ||
| 107 | static_assert(!CXXIter::util::BackInsertableContainerTemplate<std::multimap , TestValue>); | ||
| 108 | static_assert(!CXXIter::util::BackInsertableContainerTemplate<std::unordered_map , TestValue>); | ||
| 109 | static_assert(!CXXIter::util::BackInsertableContainerTemplate<std::unordered_multimap , TestValue>); | ||
| 110 | |||
| 111 | static_assert(!CXXIter::util::InsertableContainerTemplate<std::vector , TestValue>); | ||
| 112 | static_assert(!CXXIter::util::InsertableContainerTemplate<std::list , TestValue>); | ||
| 113 | static_assert(!CXXIter::util::InsertableContainerTemplate<std::deque , TestValue>); | ||
| 114 | static_assert( CXXIter::util::InsertableContainerTemplate<std::set , TestValue>); | ||
| 115 | static_assert( CXXIter::util::InsertableContainerTemplate<std::multiset , TestValue>); | ||
| 116 | static_assert( CXXIter::util::InsertableContainerTemplate<std::unordered_set , TestValue>); | ||
| 117 | static_assert( CXXIter::util::InsertableContainerTemplate<std::unordered_multiset , TestValue>); | ||
| 118 | static_assert(!CXXIter::util::InsertableContainerTemplate<std::map , TestValue>); | ||
| 119 | static_assert(!CXXIter::util::InsertableContainerTemplate<std::multimap , TestValue>); | ||
| 120 | static_assert(!CXXIter::util::InsertableContainerTemplate<std::unordered_map , TestValue>); | ||
| 121 | static_assert(!CXXIter::util::InsertableContainerTemplate<std::unordered_multimap , TestValue>); | ||
| 122 | |||
| 123 | //static_assert(!CXXIter::util::AssocContainerTemplate<std::vector ,TestKey, TestValue>); | ||
| 124 | //static_assert(!CXXIter::util::AssocContainerTemplate<std::list ,TestKey, TestValue>); | ||
| 125 | //static_assert(!CXXIter::util::AssocContainerTemplate<std::deque ,TestKey, TestValue>); | ||
| 126 | static_assert(!CXXIter::util::AssocContainerTemplate<std::set ,TestKey, TestValue>); | ||
| 127 | static_assert(!CXXIter::util::AssocContainerTemplate<std::multiset ,TestKey, TestValue>); | ||
| 128 | static_assert(!CXXIter::util::AssocContainerTemplate<std::unordered_set ,TestKey, TestValue>); | ||
| 129 | static_assert(!CXXIter::util::AssocContainerTemplate<std::unordered_multiset ,TestKey, TestValue>); | ||
| 130 | static_assert( CXXIter::util::AssocContainerTemplate<std::map ,TestKey, TestValue>); | ||
| 131 | static_assert( CXXIter::util::AssocContainerTemplate<std::multimap ,TestKey, TestValue>); | ||
| 132 | static_assert( CXXIter::util::AssocContainerTemplate<std::unordered_map ,TestKey, TestValue>); | ||
| 133 | static_assert( CXXIter::util::AssocContainerTemplate<std::unordered_multimap ,TestKey, TestValue>); | ||
| 134 | |||
| 135 | // std::array concept | ||
| 136 | static_assert( CXXIter::util::StdArrayContainer<std::array<TestValue, 3>, TestValue>); | ||
| 137 | static_assert(!CXXIter::util::StdArrayContainer<std::vector<TestValue>, TestValue>); | ||
| 138 | static_assert(!CXXIter::util::StdArrayContainer<std::list<TestValue>, TestValue>); | ||
| 139 | static_assert(!CXXIter::util::StdArrayContainer<std::deque<TestValue>, TestValue>); | ||
| 140 | static_assert(!CXXIter::util::StdArrayContainer<std::set<TestValue>, TestValue>); | ||
| 141 | static_assert(!CXXIter::util::StdArrayContainer<std::multiset<TestValue>, TestValue>); | ||
| 142 | static_assert(!CXXIter::util::StdArrayContainer<std::unordered_set<TestValue>, TestValue>); | ||
| 143 | static_assert(!CXXIter::util::StdArrayContainer<std::unordered_multiset<TestValue>, TestValue>); | ||
| 144 | static_assert(!CXXIter::util::StdArrayContainer<std::map<TestKey, TestValue>, TestValue>); | ||
| 145 | static_assert(!CXXIter::util::StdArrayContainer<std::multimap<TestKey, TestValue>, TestValue>); | ||
| 146 | static_assert(!CXXIter::util::StdArrayContainer<std::unordered_map<TestKey, TestValue>, TestValue>); | ||
| 147 | static_assert(!CXXIter::util::StdArrayContainer<std::unordered_multimap<TestKey, TestValue>, TestValue>); | ||
| 148 | 2 | } | |
| 149 | |||
| 150 | 8 | TEST(CXXIter, is_pair) { | |
| 151 | static_assert(!CXXIter::util::is_pair< int >); | ||
| 152 | static_assert(!CXXIter::util::is_pair< float >); | ||
| 153 | static_assert(!CXXIter::util::is_pair< std::vector<int> >); | ||
| 154 | static_assert(!CXXIter::util::is_pair< std::vector<std::pair<int, int>> >); | ||
| 155 | |||
| 156 | static_assert( CXXIter::util::is_pair< std::pair<int, int> >); | ||
| 157 | static_assert( CXXIter::util::is_pair< std::pair<float, float> >); | ||
| 158 | static_assert( CXXIter::util::is_pair< std::pair<float, int> >); | ||
| 159 | static_assert( CXXIter::util::is_pair< std::pair<int, std::vector<int>> >); | ||
| 160 | 2 | } | |
| 161 | |||
| 162 | 8 | TEST(CXXIter, is_optional) { | |
| 163 | static_assert(!CXXIter::util::is_optional< int >); | ||
| 164 | static_assert(!CXXIter::util::is_optional< float >); | ||
| 165 | static_assert(!CXXIter::util::is_optional< std::vector<int> >); | ||
| 166 | static_assert(!CXXIter::util::is_optional< std::vector<std::optional<int>> >); | ||
| 167 | |||
| 168 | static_assert( CXXIter::util::is_optional< std::optional<int> >); | ||
| 169 | static_assert( CXXIter::util::is_optional< std::optional<float> >); | ||
| 170 | static_assert( CXXIter::util::is_optional< std::optional<std::string> >); | ||
| 171 | static_assert( CXXIter::util::is_optional< std::optional<std::pair<float, int>> >); | ||
| 172 | static_assert( CXXIter::util::is_optional< std::optional<std::vector<int>> >); | ||
| 173 | 2 | } | |
| 174 |