47 using LERR_(INDEX_BOUNDS);
74 setVal (getVal() -
explore(ext_).resultSum());
80 return i+ii +
explore(ext_).resultSum();
90 operator= (
Num && oNum)
100 std::swap (
static_cast<Dummy&
> (num1)
101 ,
static_cast<Dummy&
> (num2));
161 CHECK (elms.size() == 7);
162 CHECK (elms.back() == 13);
163 CHECK (elms[3] == 3);
164 CHECK (join (elms,
"-") ==
"1-1-2-3-5-8-13"_expect);
165 CHECK (toString(elms) ==
"[1, 1, 2, 3, 5, 8, 13]"_expect);
186 CHECK (isnil (builder));
190 CHECK (2 == builder.
size());
191 CHECK (3 == builder[1].getVal());
194 CHECK (4 == builder.
size());
196 CHECK (7 == builder.
size());
199 CHECK ( isnil(builder));
200 CHECK (not isnil(elms));
201 CHECK (7 == elms.
size());
202 CHECK (elms[0].getVal() == (3+1)*3);
203 CHECK (elms[0].calc(1) == 3 + 1 + (3+3+3));
204 CHECK (elms[1].getVal() == (2+1)*1);
205 CHECK (elms[1].calc(1) == 2 + 1 + (1+1));
206 CHECK (isLimited (1, elms[2].getVal(), 100'000'000));
207 CHECK (isLimited (1, elms[3].getVal(), 100'000'000));
208 CHECK (elms[4].getVal() == 5);
209 CHECK (elms[5].getVal() == 5);
210 CHECK (elms[6].getVal() == 5);
211 CHECK (elms[6].calc(1) == 5+1);
217 auto urgh = array<char,5>{
"Urgh"};
218 auto phi = (1+sqrtf(5))/2;
220 builder.
append (urgh, phi, -1);
221 CHECK (3 == builder.
size());
224 CHECK (3 == elms.
size());
225 CHECK (elms[0] == *
reinterpret_cast<const uint32_t*
> (
"Urgh"));
226 CHECK (elms[1] == *
reinterpret_cast<uint32_t*
> (&phi));
227 CHECK (elms[2] == uint32_t(-1));
233 VecI seq = getTestSeq_int<VecI> (10);
235 CHECK (10 == builder.
size());
237 auto elms = builder.
build();
238 CHECK (10 == elms.size());
239 CHECK (join (elms,
"-") ==
"0-1-2-3-4-5-6-7-8-9"_expect);
279 CHECK (1 == builder.
size());
285 CHECK (
sizeof(Num<1>) <
sizeof(Num<5>));
286 VERIFY_FAIL (
"Unable to place element of type Num<5u> (size="
288 CHECK (1 == builder.
size());
293 VERIFY_FAIL (
"Unable to handle (trivial-)destructor for element type long, "
294 "since this container has been primed to use virtual-baseclass-destructors."
296 CHECK (1 == builder.
size());
301 CHECK (6 == builder.
size());
307 VERIFY_FAIL (
"Several-container is unable to accommodate further element of type Dummy"
309 CHECK (10 == builder.
size());
320 CHECK (5 == builder.
size());
324 CHECK (19 == builder.
size());
325 CHECK (builder.
size() > INITIAL_ELM_CNT);
331 VERIFY_FAIL (
"Unable to handle (trivial-)destructor for element type ShortBlocker, "
332 "since this container has been primed to use virtual-baseclass-destructors."
333 , builder.
emplace<ShortBlocker>() );
334 CHECK (19 == builder.
size());
336 CHECK (
sizeof(ShortBlocker) <
sizeof(Num<5>));
343 CHECK (20 == builder.
size());
350 VERIFY_FAIL (
"unable to move elements of mixed unknown detail type, which are not trivially movable"
354 auto elms = builder.
build();
355 CHECK (20 == elms.size());
357 for (
uint i=0; i<=18; ++i)
358 CHECK (elms[i].calc(i) == 5 + i + (5+5+5+5+5));
359 CHECK (elms.back().calc(0) == 1 + 0 + (1));
368 CHECK ( 0 == builder.
size());
372 string BFR{
"starship is"};
374 CHECK (11 == builder.
size());
380 builder.
append (int64_t(32));
381 CHECK (12 == builder.
size());
387 builder.
emplace<ShortBlocker> (
'c');
390 builder.
append (
int(
'o'), long(
'o'));
391 CHECK (15 == builder.
size());
394 VERIFY_FAIL (
"Unable to place element of type Num<5u>"
395 , builder.
append (Num<5>{}) );
396 CHECK (
sizeof(Num<5>) >
sizeof(int64_t));
409 CHECK (
sizeof(NonTrivial) <=
sizeof(int64_t));
410 VERIFY_FAIL (
"Unsupported kind of destructor for element type SeveralBuilder_test::check_ErrorHandling()::NonTrivial"
411 , builder.
append (NonTrivial{}) );
416 CHECK (16 == builder.
size());
420 VERIFY_FAIL (
"Several-container is unable to accommodate further element of type char; "
421 "storage reserve (128 bytes ≙ 16 elms) exhausted and unable to move "
422 "elements of mixed unknown detail type, which are not trivially movable."
426 auto elms = builder.
build();
427 CHECK (16 == elms.size());
428 CHECK (join(elms,
"·") ==
"s·t·a·r·s·h·i·p· ·i·s· ·c·o·o·l"_expect);
436 CHECK (1 == builder.
size());
441 NOTREACHED (
"did not throw");
451 CHECK (1 == builder.
size());
455 auto elms = builder.
build();
456 CHECK (2 == elms.size());
457 CHECK (elms.front().calc(1) == 3 + 1 + (42+42+42));
458 CHECK (elms.back().calc(5) == 3 + 5 + (23+23+23));
480 auto loc = [](
auto& something){
return util::addrID (something); };
481 auto calcSpread = [&](
auto& several){
return loc(several[1]) - loc(several[0]); };
485 CHECK (21 == elms[0]);
486 CHECK (34 == elms[1]);
487 CHECK (55 == elms[2]);
488 CHECK (3 == elms.
size());
489 CHECK (
sizeof(elms) ==
sizeof(
void*));
491 CHECK (
sizeof(
int) ==
alignof(
int));
492 size_t spread = calcSpread (elms);
493 CHECK (spread ==
sizeof(
int));
494 CHECK (loc(elms.
back()) == loc(elms.
front()) + 2*spread);
504 auto elms = makeSeveral<Ali>().fillElm(5).build();
505 CHECK (5 == elms.size());
506 CHECK (
sizeof(elms) ==
sizeof(
void*));
508 size_t spread = calcSpread (elms);
509 CHECK (spread ==
alignof(Ali));
510 CHECK (loc(elms.front()) %
alignof(Ali) == 0);
511 CHECK (loc(elms.back()) == loc(elms.front()) + 4*spread);
515 auto elms = makeSeveral<ShortBlocker>().fillElm(5).build();
517 auto v0 = elms[0].val;
auto p0 = loc(elms[0]);
518 auto v1 = elms[1].val;
auto p1 = loc(elms[1]);
519 auto v2 = elms[2].val;
auto p2 = loc(elms[2]);
520 auto v3 = elms[3].val;
auto p3 = loc(elms[3]);
521 auto v4 = elms[4].val;
auto p4 = loc(elms[4]);
523 CHECK (5 == elms.size());
524 auto moved = move(elms);
525 CHECK (5 == moved.size());
526 CHECK (loc(elms) != loc(moved));
527 CHECK (isnil (elms));
529 CHECK (loc(moved[0]) == p0);
530 CHECK (loc(moved[1]) == p1);
531 CHECK (loc(moved[2]) == p2);
532 CHECK (loc(moved[3]) == p3);
533 CHECK (loc(moved[4]) == p4);
535 CHECK (moved[0].val == v0);
536 CHECK (moved[1].val == v1);
537 CHECK (moved[2].val == v2);
538 CHECK (moved[3].val == v3);
539 CHECK (moved[4].val == v4);
541 CHECK (calcSpread(moved) ==
sizeof(ShortBlocker));
560 size_t expectedAlloc;
564 auto builder = makeSeveral<Dummy>()
568 size_t elmSiz =
sizeof(
Dummy);
569 size_t buffSiz = elmSiz * builder.capacity();
570 size_t headerSiz =
sizeof(ArrayBucket<Dummy>);
571 expectedAlloc = headerSiz + buffSiz;
578 elms = builder.build();
580 CHECK (elms.
size() == 55);
585 auto others = move(elms);
586 CHECK (elms.
size() == 0);
587 CHECK (others.size() == 55);
593 CHECK (others.size() == 0);
606 CHECK (allotted == 0);
608 auto builder = makeSeveral<Dummy>()
613 size_t buffSiz =
sizeof(
Dummy) * builder.capacity();
614 size_t headerSiz =
sizeof(ArrayBucket<Dummy>);
615 expectedAlloc = headerSiz + buffSiz;
616 CHECK (4 == builder.size());
617 CHECK (4 == builder.capacity());
619 CHECK (expectedAlloc == clu.
numBytes());
621 builder.append (
Dummy{23});
622 CHECK (8 == builder.capacity());
624 buffSiz =
sizeof(
Dummy) * builder.capacity();
625 expectedAlloc = headerSiz + buffSiz;
627 CHECK (expectedAlloc == clu.
numBytes());
635 CHECK (5 == builder.size());
636 CHECK (9 <= builder.capacity());
638 buffSiz =
sizeof(
Dummy) * builder.capacity();
639 expectedAlloc = headerSiz + buffSiz;
647 CHECK (5 == builder.size());
648 CHECK (5 == builder.capacity());
652 elms = builder.build();
653 CHECK (5 == elms.
size());
654 CHECK (23 == elms.
back().getVal());
655 CHECK (55 == extraDummy.
getVal());
657 CHECK (5 == elms.
size());
658 CHECK (23 == elms.
back().getVal());
Memory management for the low-level model (render nodes network).
A pile of objects sharing common allocation and lifecycle.
size_t numExtents() const
static constexpr size_t max_size()
Maximum individual allocation size that can be handled.
Builder to create and populate a lib::Several<I>.
SeveralBuilder && fillElm(size_t cntNew, ARGS &&...args)
emplace a number of elements of the defined element type E
size_t capReserve() const
SeveralBuilder && appendAll(IT &&data)
append a copy of all values exposed through an iterator
SeveralBuilder && emplace(ARGS &&...args)
create a new content element within the managed storage
SeveralBuilder && append(VAL &&val, VALS &&...vals)
append copies of one or several arbitrary elements
SeveralBuilder && reserve(size_t cntElm=1, size_t elmSiz=reqSiz< TY >())
ensure up-front that a desired capacity is allocated
Several< I > build()
Terminal Builder: complete and lock the collection contents.
Abstraction: Fixed array of elements.
A Dummy object for tests.
static void activateCtorFailure(bool indeed=true)
void check_ErrorHandling()
void check_CustomAllocator()
void check_ElementStorage()
C++ standard compliant custom allocator adapter backed by the TrackingAllocator and the MemoryPool de...
static size_t numAlloc(Literal pool=GLOBAL)
get active allocation count for mem-pool
static size_t numBytes(Literal pool=GLOBAL)
calculate currently allotted Bytes for mem-pool
static size_t use_count(Literal pool=GLOBAL)
determine number of active front-end handles
static HashVal checksum(Literal pool=GLOBAL)
get Checksum for specific mem-pool
Instance tracking sub-dummy.
std::array< int, i > ext_
Num(Num &&oNum) noexcept
allow for move construction
friend void swap(Num &num1, Num &num2)
long calc(int ii) override
a dummy API operation
Any copy and copy construction prohibited.
Building tree expanding and backtracking evaluations within hierarchical scopes.
Implementation namespace for support and library code.
auto explore(IT &&srcSeq)
start building a IterExplorer by suitably wrapping the given iterable source.
int rani(uint bound=_iBOUND())
SeveralBuilder< I, E > makeSeveral()
Entrance Point: start building a lib::Several instance.
Test runner and basic definitions for tests.
constexpr bool isLimited(NB lowerBound, NUM val, NB upperBound)
size_t addrID(X const &x)
generate an unique numeric ID based on the referred entity
std::string toString(TY const &val) noexcept
get some string representation of any object, reliably.
string join(COLL &&coll, string const &delim=", ")
enumerate a collection's contents, separated by delimiter.
bool isnil(lib::time::Duration const &dur)
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Builder to create and populate instances of the lib::Several container.
A non-copyable struct with 16bit alignment.
ShortBlocker(short r=1+rani(1 '000))
some bits of unit test helper code to fabricate collections with test data
A collection of frequently used helper functions to support unit testing.
#define VERIFY_FAIL(FAILURE_MSG, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises a std::exception, which additionally contains some FAI...
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Unittest helper code: a custom allocator to track memory usage.
unittest helper code: test dummy objects to track instances.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...