38 using LERR_(ITER_EXHAUST);
41 using std::make_tuple;
47 auto num5() {
return NumIter{0,5}; }
49 template<u
int N, u
int S=0>
50 auto numS() {
return explore(num5()).transform([](
int i){
return i*N +
S; }); }
51 auto num31(){
return numS<3,1>(); }
52 auto num32(){
return numS<3,2>(); }
53 auto num33(){
return numS<3,3>(); }
55 auto hexed = [](
int i){
return util::showHash(i,1); };
63 return util::join (std::forward<II> (ii),
"-");
67 #define TYPE(_EXPR_) showType<decltype(_EXPR_)>() 104 auto a = std::array{1u,2u,3u};
105 auto v = std::vector{{2l,3l}};
108 for (
auto [u,l] :
zip(a,v))
114 CHECK (*it ==
"«tuple<ulong, long&>»──(0,2)"_expect );
116 CHECK (*it ==
"«tuple<ulong, long&>»──(1,3)"_expect );
128 CHECK (materialise (num5() ) ==
"0-1-2-3-4"_expect);
129 CHECK (materialise (num31() ) ==
"1-4-7-10-13"_expect);
130 CHECK (materialise (num33() ) ==
"3-6-9-12-15"_expect);
131 CHECK (materialise (num32()
133 ) ==
"02-05-08-0B-0E"_expect);
141 auto t1 = make_tuple (41u, 0.61803,
'6');
142 CHECK (t1 ==
"«tuple<uint, double, char>»──(41,0.61803,6)"_expect );
144 auto t1f = mapEach (t1, [](
auto v){
return v+1; });
145 CHECK (t1f ==
"«tuple<uint, double, int>»──(42,1.61803,55)"_expect );
147 auto t1ff = mapEach (t1, [](
auto& v){ v += 1;
return v; });
148 CHECK (t1ff ==
"«tuple<uint, double, char>»──(42,1.61803,7)"_expect );
149 CHECK (t1f ==
"«tuple<uint, double, int>»──(42,1.61803,55)"_expect );
150 CHECK (t1 ==
"«tuple<uint, double, char>»──(42,1.61803,7)"_expect );
153 tuple<char, char&> t2{get<2>(t1), get<2>(t1ff)};
154 CHECK (t2 ==
"«tuple<char, char&>»──(7,7)"_expect );
156 auto t2f = mapEach (t2, [](
auto& v){ v -= 1;
return v; });
157 CHECK (t2f ==
"«tuple<char, char>»──(6,6)"_expect );
158 CHECK (t2 ==
"«tuple<char, char&>»──(6,6)"_expect);
159 CHECK (t1ff ==
"«tuple<uint, double, char>»──(42,1.61803,6)"_expect );
160 CHECK (t1 ==
"«tuple<uint, double, char>»──(42,1.61803,7)"_expect );
163 auto refr = [](
auto&& v) -> decltype(
auto) {
return v; };
165 CHECK (TYPE (refr(five)) ==
"int&"_expect);
166 CHECK (TYPE (refr(5 )) ==
"int&"_expect);
168 auto t2r = mapEach (t2, refr);
169 CHECK (t2r ==
"«tuple<char&, char&>»──(6,6)"_expect );
171 forEach (t2r, [](
auto& v){ v +=23; });
172 CHECK (t2r ==
"«tuple<char&, char&>»──(M,M)"_expect );
173 CHECK (t2 ==
"«tuple<char, char&>»──(M,M)"_expect );
174 CHECK (t2f ==
"«tuple<char, char>»──(6,6)"_expect );
175 CHECK (t1 ==
"«tuple<uint, double, char>»──(42,1.61803,7)"_expect );
176 CHECK (t1ff ==
"«tuple<uint, double, char>»──(42,1.61803,M)"_expect );
180 template<
typename...ITS>
182 buildIterTuple (ITS&& ...iters)
184 return make_tuple (
lib::explore (std::forward<ITS> (iters)) ...);
195 auto arry = std::array{3u,2u,1u};
196 auto iTup = buildIterTuple (num5(), arry);
198 CHECK (TYPE(iTup) ==
"tuple<IterExplorer<iter_explorer::BaseAdapter<NumIter<int> > >, " 199 "IterExplorer<iter_explorer::BaseAdapter<iter_explorer::StlRange<array<uint, 3ul>&> > > >"_expect);
202 auto iterate_it = [](
auto& it){ ++it; };
203 auto access_val = [](
auto& it){
return *it; };
205 forEach (iTup, iterate_it);
206 auto vTup = mapEach (iTup, access_val);
207 CHECK (vTup ==
"«tuple<int, uint>»──(1,2)"_expect);
209 using ITup = decltype(iTup);
217 ProductCore(ITup&& iterTup)
218 : iters_{move (iterTup)}
226 forEach (iters_, [&](
auto& it){ active = active and bool(it); });
233 return unConst(iters_);
239 forEach (iters_, [](
auto& it){ ++it; });
245 auto ii =
explore (ProductCore{buildIterTuple (num5(), arry)})
246 .transform ([&](ITup& iTup){
return mapEach (iTup, access_val); })
250 CHECK (TYPE(ii) ==
"IterExplorer<" 253 "iter_explorer::Transformer<" 254 "iter_explorer::BaseAdapter<" 257 "IterZip_test::demo_construction()::ProductCore> > >, " 269 CHECK (materialise (ii) ==
"«tuple<int, uint>»──(0,3)-" 270 "«tuple<int, uint>»──(1,2)-" 271 "«tuple<int, uint>»──(2,1)"_expect);
284 zip (num31(), num32(), num33())
286 ==
"«tuple<uint&, uint&, uint&>»──(1,2,3)-" 287 "«tuple<uint&, uint&, uint&>»──(4,5,6)-" 288 "«tuple<uint&, uint&, uint&>»──(7,8,9)-" 289 "«tuple<uint&, uint&, uint&>»──(10,11,12)-" 290 "«tuple<uint&, uint&, uint&>»──(13,14,15)"_expect);
293 izip (num31(), num32(), num33())
295 ==
"«tuple<ulong, uint&, uint&, uint&>»──(0,1,2,3)-" 296 "«tuple<ulong, uint&, uint&, uint&>»──(1,4,5,6)-" 297 "«tuple<ulong, uint&, uint&, uint&>»──(2,7,8,9)-" 298 "«tuple<ulong, uint&, uint&, uint&>»──(3,10,11,12)-" 299 "«tuple<ulong, uint&, uint&, uint&>»──(4,13,14,15)"_expect);
302 auto s6 = std::array{1,1,2,3,5,8};
305 CHECK (TYPE(s6) ==
"array<int, 6ul>"_expect );
306 CHECK (TYPE(s3) ==
"initializer_list<int>"_expect );
307 CHECK (TYPE(s0) ==
"NumIter<uint>"_expect );
312 ==
"«tuple<int&, int&, int&, char>»──(1,1,1,a)-" 313 "«tuple<int&, int&, int&, char>»──(1,1,1,b)-" 314 "«tuple<int&, int&, int&, char>»──(2,2,2,c)-" 315 "«tuple<int&, int&, int&, char>»──(3,3,3,d)-" 316 "«tuple<int&, int&, int&, char>»──(5,5,5,e)-" 317 "«tuple<int&, int&, int&, char>»──(8,8,8,f)"_expect);
322 ==
"«tuple<int&, int const&, int&, char>»──(1,3,1,a)-" 323 "«tuple<int&, int const&, int&, char>»──(1,2,1,b)-" 324 "«tuple<int&, int const&, int&, char>»──(2,1,2,c)"_expect);
345 ==
"«tuple<char, int, int const&, int const&>»──(a,-1,3,3)-" 346 "«tuple<char, int, int const&, int const&>»──(b,0,2,2)-" 347 "«tuple<char, int, int const&, int const&>»──(c,1,1,1)"_expect);
354 ,numS<17,170>().transform(hexed)
359 ==
"«tuple<ulong, int&, int&, string&, double, int const&>»──(0,1,1,AA,1.618034,3)-" 360 "«tuple<ulong, int&, int&, string&, double, int const&>»──(1,1,1,BB,2.618034,2)-" 361 "«tuple<ulong, int&, int&, string&, double, int const&>»──(2,2,3,CC,3.618034,1)"_expect);
370 auto vec = std::vector{1,5};
371 auto arr = std::array{2,3};
374 auto i1 =
izip (vec,arr);
376 CHECK (*i1 ==
"«tuple<ulong, int&, int&>»──(0,1,2)"_expect );
378 CHECK (*i1 ==
"«tuple<ulong, int&, int&>»──(0,5,2)"_expect );
380 CHECK (join(vec) ==
"5, 5"_expect );
381 CHECK (join(arr) ==
"2, 3"_expect );
384 auto i2 =
izip (
explore(vec).transform([](uint v){
return v-1; })
387 CHECK (*i2 ==
"«tuple<ulong, uint&, int&>»──(0,4,2)"_expect );
391 CHECK (*i2 ==
"«tuple<ulong, uint&, int&>»──(9,9,9)"_expect );
394 CHECK (*i2 ==
"«tuple<ulong, uint&, int&>»──(1,4,3)"_expect );
395 CHECK (join(vec) ==
"5, 5"_expect );
396 CHECK (join(arr) ==
"9, 3"_expect );
413 zip (num31(), num32(), num33())
415 ==
"«tuple<uint&, uint&, uint&>»──(1,2,3)-" 416 "«tuple<uint&, uint&, uint&>»──(4,5,6)-" 417 "«tuple<uint&, uint&, uint&>»──(7,8,9)-" 418 "«tuple<uint&, uint&, uint&>»──(10,11,12)-" 419 "«tuple<uint&, uint&, uint&>»──(13,14,15)"_expect);
423 zip (num31(), num32(), num33())
424 . transform([](
auto& it){
auto [a,b,c] = *it;
428 ==
"6-15-24-33-42"_expect);
432 zip (num31(), num32(), num33())
433 .
filter ([](
auto& it){
auto [a,b,c] = *it;
434 return not ((a+b+c) % 2);
437 ==
"«tuple<uint&, uint&, uint&>»──(1,2,3)-" 438 "«tuple<uint&, uint&, uint&>»──(7,8,9)-" 439 "«tuple<uint&, uint&, uint&>»──(13,14,15)"_expect);
442 CHECK (
zip (num31(), num32(), num33())
443 .
reduce ([](
auto& it){
auto [a,b,c] = *it;
473 ==
"1-4-7-10-13"_expect);
477 .expand ([](
int i){
return NumIter{noneg(i-1),i}; })
480 ==
"1-0-4-3-2-1-0-7-6-5-4-3-2-1-0-10-9-8-7-6-5-4-3-2-1-0-13-12-11-10-9-8-7-6-5-4-3-2-1-0"_expect);
484 .expand ([](
int i){
return NumIter{noneg(i-2),i-1}; })
487 ==
"1-4-2-0-7-5-3-1-10-8-6-4-2-0-13-11-9-7-5-3-1"_expect);
493 .expand ([](
int i){
return NumIter{noneg(i-1),i}; })
496 .expand ([](
int i){
return NumIter{noneg(i-2),i-1}; })
500 ==
"«tuple<int, uint, uint>»──(10,1,1)-" 501 "«tuple<int, uint, uint>»──(11,0,4)-" 502 "«tuple<int, uint, uint>»──(12,4,2)-" 503 "«tuple<int, uint, uint>»──(13,3,0)-" 504 "«tuple<int, uint, uint>»──(14,2,7)-" 505 "«tuple<int, uint, uint>»──(15,1,5)-" 506 "«tuple<int, uint, uint>»──(16,0,3)-" 507 "«tuple<int, uint, uint>»──(17,7,1)-" 508 "«tuple<int, uint, uint>»──(18,6,10)-" 509 "«tuple<int, uint, uint>»──(19,5,8)-" 510 "«tuple<int, uint, uint>»──(20,4,6)-" 511 "«tuple<int, uint, uint>»──(21,3,4)-" 512 "«tuple<int, uint, uint>»──(22,2,2)-" 513 "«tuple<int, uint, uint>»──(23,1,0)-" 514 "«tuple<int, uint, uint>»──(24,0,13)-" 515 "«tuple<int, uint, uint>»──(25,10,11)-" 516 "«tuple<int, uint, uint>»──(26,9,9)-" 517 "«tuple<int, uint, uint>»──(27,8,7)-" 518 "«tuple<int, uint, uint>»──(28,7,5)-" 519 "«tuple<int, uint, uint>»──(29,6,3)-" 520 "«tuple<int, uint, uint>»──(30,5,1)"_expect);
526 .expand ([](
int i){
return NumIter{noneg(i-1),i}; })
528 .expand ([](
int i){
return NumIter{noneg(i-2),i-1}; })
532 ==
"«tuple<int, uint, uint>»──(10,1,1)-" 533 "«tuple<int, uint, uint>»──(10,0,4)-" 534 "«tuple<int, uint, uint>»──(10,4,2)-" 535 "«tuple<int, uint, uint>»──(10,3,0)-" 536 "«tuple<int, uint, uint>»──(10,2,7)-" 537 "«tuple<int, uint, uint>»──(10,1,5)-" 538 "«tuple<int, uint, uint>»──(10,0,3)-" 539 "«tuple<int, uint, uint>»──(10,7,1)-" 540 "«tuple<int, uint, uint>»──(10,6,10)-" 541 "«tuple<int, uint, uint>»──(10,5,8)-" 542 "«tuple<int, uint, uint>»──(10,4,6)-" 543 "«tuple<int, uint, uint>»──(10,3,4)-" 544 "«tuple<int, uint, uint>»──(10,2,2)-" 545 "«tuple<int, uint, uint>»──(10,1,0)-" 546 "«tuple<int, uint, uint>»──(10,0,13)-" 547 "«tuple<int, uint, uint>»──(10,10,11)-" 548 "«tuple<int, uint, uint>»──(10,9,9)-" 549 "«tuple<int, uint, uint>»──(10,8,7)-" 550 "«tuple<int, uint, uint>»──(10,7,5)-" 551 "«tuple<int, uint, uint>»──(10,6,3)-" 552 "«tuple<int, uint, uint>»──(10,5,1)"_expect);
auto explore(IT &&srcSeq)
start building a IterExplorer by suitably wrapping the given iterable source.
auto izip(ITS &&...iters)
tuple-combining iterator prefixed by index sequence
bool filter(Placement< DummyMO > const &candidate)
a filter predicate to pick some objects from a resultset.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
NUM constexpr noneg(NUM val)
cut a numeric value to be >=0
Helpers typically used while writing tests.
Iterator builder to combine several iterables into a tuple sequence.
Implementation namespace for support and library code.
Enumerate all "numbers" within a range.
Simplistic test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A collection of frequently used helper functions to support unit testing.
Custom-Datatype 1: uses std::hash extension point.
void forEach(TUP &&tuple, FUN fun)
Tuple iteration: perform some arbitrary operation on each element of a tuple.
Building tree expanding and backtracking evaluations within hierarchical scopes.
auto mapEach(TUP &&tuple, FUN fun)
Apply some arbitrary function onto all elements of a tuple.
void verify_exploration()
NumIter< INT > eachNum(INT start=std::numeric_limits< INT >::min(), INT end=std::numeric_limits< INT >::max())
convenience function to iterate "each number"
auto zip(ITS &&...iters)
Build a tuple-combining iterator builder.