Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
noexcept_construction_test.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
61# include <cstddef>
62# include <memory>
63# include <stdexcept>
64# include <string>
65# include <type_traits>
66# include <utility>
67
68# include <gtest/gtest.h>
69
70# include <ah-mapping.H>
71# include <htlist.H>
72# include <tpl_array.H>
73# include <tpl_avl.H>
74# include <tpl_avlRk.H>
75# include <tpl_binTree.H>
76# include <tpl_dynArrayHeap.H>
77# include <tpl_dynMapTree.H>
78# include <tpl_dynSetTree.H>
79# include <tpl_hRbTree.H>
80# include <tpl_hRbTreeRk.H>
81# include <tpl_odhash.H>
82# include <tpl_olhash.H>
83# include <tpl_rand_tree.H>
84# include <tpl_rbRk.H>
85# include <tpl_rb_tree.H>
86# include <tpl_splay_tree.H>
87# include <tpl_splay_treeRk.H>
88# include <tpl_tdRbTree.H>
89# include <tpl_tdRbTreeRk.H>
90# include <tpl_treap.H>
91# include <tpl_treapRk.H>
92
93using namespace Aleph;
94
95namespace
96{
97 // What a type of the user throws when the test asks it to
98 struct Asked_Failure : std::runtime_error
99 {
100 Asked_Failure() : std::runtime_error("an operation of the user failed") {}
101 };
102
103 // How many of the operations below that may throw still succeed before
104 // one throws; negative, none throws
105 long countdown = -1;
106
107 void maybe_fail()
108 {
109 if (countdown == 0)
110 throw Asked_Failure();
111 if (countdown > 0)
112 --countdown;
113 }
114
115 // Makes the operation k of the types below throw, for the life of the
116 // object, and none after
117 struct Failing_At
118 {
119 explicit Failing_At(const long k) noexcept { countdown = k; }
120 ~Failing_At() { countdown = -1; }
121 Failing_At(const Failing_At &) = delete;
122 Failing_At & operator = (const Failing_At &) = delete;
123 };
124
125 // Builds with f, with each operation of the user failing in turn, until
126 // one succeeds: f must throw Asked_Failure or succeed, never end the
127 // program. Returns how many failures reached the caller
128 template <class F>
129 long failures_through(F && f)
130 {
131 for (long k = 0; ; ++k)
132 {
133 const Failing_At failing(k);
134 try
135 {
136 f();
137 return k;
138 }
139 catch (const Asked_Failure &)
140 {
141 // the next operation fails now
142 }
143 }
144 }
145
146 // A tree built by default with a comparison whose default construction
147 // throws must let what it throws through, and not say that it cannot
148 // throw
149 template <class Tree>
150 void expect_that_the_default_construction_lets_the_comparison_throw()
151 {
152 EXPECT_FALSE(std::is_nothrow_default_constructible_v<Tree>);
153 EXPECT_GT(failures_through([] { Tree tree; }), 0);
154 }
155
156 // A tree built from a temporary comparison: what the copy of it throws,
157 // if it throws, must reach the caller, and the constructor must not say
158 // that it cannot throw
159 template <class Tree, class Less>
160 void expect_that_the_copy_of_the_comparison_lets_it_throw()
161 {
162 if (failures_through([] { Tree tree((Less())); }) > 0)
163 {
164 EXPECT_FALSE((std::is_nothrow_constructible_v<Tree, Less>));
165 }
166 }
167
168 // A key whose default construction may throw; the rest cannot
169 struct Key_Default_Throws
170 {
171 int value = 0;
172
173 Key_Default_Throws() { maybe_fail(); }
174 Key_Default_Throws(const int v) noexcept : value(v) {}
175
176 friend bool operator < (const Key_Default_Throws & a, const Key_Default_Throws & b) noexcept
177 {
178 return a.value < b.value;
179 }
180
181 friend bool operator == (const Key_Default_Throws & a, const Key_Default_Throws & b) noexcept
182 {
183 return a.value == b.value;
184 }
185 };
186
187 // What the keys below count of themselves
188 struct Key_Counts
189 {
190 long defaults = 0; // default constructions
191 long copies = 0;
192 long moves = 0;
193 };
194
195 Key_Counts key_counts;
196
197 // What f() adds to those counts
198 template <class F>
199 Key_Counts counted_in(F && f)
200 {
201 const Key_Counts before = key_counts;
202 f();
203 return {key_counts.defaults - before.defaults, key_counts.copies - before.copies,
204 key_counts.moves - before.moves};
205 }
206
207 // What the move of an empty tree of the type builds
208 template <class Tree>
209 Key_Counts built_by_the_move_of_an_empty()
210 {
211 Tree tree;
212 return counted_in([&tree] { Tree taken(std::move(tree)); (void) taken; });
213 }
214
215 // What the move of a set of five keys builds, which takes them all
216 template <class Set, class Key>
217 Key_Counts built_by_the_move_of_a_set_of_five()
218 {
219 Set set;
220 for (int i = 0; i < 5; ++i)
221 (void) set.insert(Key(i));
222 return counted_in([&set]
223 {
224 Set taken(std::move(set));
225 EXPECT_EQ(taken.size(), 5u);
226 EXPECT_TRUE(set.is_empty());
227 });
228 }
229
230 // A key that counts how it is built, and whose default construction and
231 // whose move may throw or not: the kinds of key that the header node of
232 // a tree that takes the nodes of another tells apart. Its copy may
233 // always throw
234 template <bool Nothrow_Default, bool Nothrow_Move>
235 struct Counted_Key
236 {
237 int value = 0;
238
239 Counted_Key() noexcept(Nothrow_Default)
240 {
241 ++key_counts.defaults;
242 if constexpr (not Nothrow_Default)
243 maybe_fail();
244 }
245
246 Counted_Key(const int v) noexcept : value(v) {}
247
248 Counted_Key(const Counted_Key & k) : value(k.value)
249 {
250 ++key_counts.copies;
251 maybe_fail();
252 }
253
254 Counted_Key(Counted_Key && k) noexcept(Nothrow_Move) : value(k.value)
255 {
256 ++key_counts.moves;
257 if constexpr (not Nothrow_Move)
258 maybe_fail();
259 }
260
261 Counted_Key & operator = (const Counted_Key & k)
262 {
263 maybe_fail();
264 value = k.value;
265 return *this;
266 }
267
268 Counted_Key & operator = (Counted_Key && k) noexcept(Nothrow_Move)
269 {
270 if constexpr (not Nothrow_Move)
271 maybe_fail();
272 value = k.value;
273 return *this;
274 }
275
276 friend bool operator < (const Counted_Key & a, const Counted_Key & b) noexcept
277 {
278 return a.value < b.value;
279 }
280
281 friend bool operator == (const Counted_Key & a, const Counted_Key & b) noexcept
282 {
283 return a.value == b.value;
284 }
285 };
286
287 // Built by default without throwing: a header node builds it so, as it
288 // always did, though its move may throw
289 using Key_Built_By_Default = Counted_Key<true, false>;
290
291 // Its default construction may throw, and its move cannot: a header node
292 // takes that of the same header node of the other tree
293 using Key_Taken = Counted_Key<false, true>;
294
295 // Both may throw, as in a class with a copy written by hand and no move:
296 // a header node builds it by default, and the move of the tree may throw
297 using Key_That_May_Always_Throw = Counted_Key<false, false>;
298
299 // A comparison whose construction, copy, move and assignments may throw,
300 // and so its swap; its call cannot
301 struct Less_Copy_Throws
302 {
303 Less_Copy_Throws() { maybe_fail(); }
304 Less_Copy_Throws(const Less_Copy_Throws &) { maybe_fail(); }
305 Less_Copy_Throws(Less_Copy_Throws &&) { maybe_fail(); }
306
307 Less_Copy_Throws & operator = (const Less_Copy_Throws &)
308 {
309 maybe_fail();
310 return *this;
311 }
312
313 Less_Copy_Throws & operator = (Less_Copy_Throws &&)
314 {
315 maybe_fail();
316 return *this;
317 }
318
319 bool operator () (const int a, const int b) const noexcept { return a < b; }
320 };
321
322 // A comparison whose default construction may throw; its copy, its
323 // move, its swap and its call cannot
324 template <typename Key>
325 struct Less_Default_Throws
326 {
327 Less_Default_Throws() { maybe_fail(); }
328
329 bool operator () (const Key & a, const Key & b) const noexcept { return a < b; }
330 };
331
332 // A comparison whose copy may throw; its default construction and its
333 // move cannot, and so neither can its swap
334 template <typename Key>
335 struct Less_Copy_Alone_Throws
336 {
337 Less_Copy_Alone_Throws() noexcept = default;
338 Less_Copy_Alone_Throws(const Less_Copy_Alone_Throws &) { maybe_fail(); }
339 Less_Copy_Alone_Throws(Less_Copy_Alone_Throws &&) noexcept = default;
340
341 Less_Copy_Alone_Throws & operator = (const Less_Copy_Alone_Throws &)
342 {
343 maybe_fail();
344 return *this;
345 }
346
347 Less_Copy_Alone_Throws & operator = (Less_Copy_Alone_Throws &&) noexcept = default;
348
349 bool operator () (const Key & a, const Key & b) const noexcept { return a < b; }
350 };
351
352 // A comparison with two copies: the one from a comparison that is not
353 // const may throw, and the one from a const one cannot
354 template <typename Key>
355 struct Less_Mutable_Copy_Throws
356 {
357 Less_Mutable_Copy_Throws() noexcept = default;
358 Less_Mutable_Copy_Throws(const Less_Mutable_Copy_Throws &) noexcept = default;
359 Less_Mutable_Copy_Throws(Less_Mutable_Copy_Throws &) { maybe_fail(); }
360 Less_Mutable_Copy_Throws(Less_Mutable_Copy_Throws &&) noexcept = default;
361 Less_Mutable_Copy_Throws & operator = (const Less_Mutable_Copy_Throws &) noexcept = default;
362 Less_Mutable_Copy_Throws & operator = (Less_Mutable_Copy_Throws &&) noexcept = default;
363
364 bool operator () (const Key & a, const Key & b) const noexcept { return a < b; }
365 };
366
367 // A comparison whose call may throw
368 struct Less_Call_Throws
369 {
370 bool operator () (const int a, const int b) const
371 {
372 maybe_fail();
373 return a < b;
374 }
375 };
376
377 // A tree template and how many header nodes it keeps, whose keys it
378 // builds; and the sets and the maps on it. None allocates when it is
379 // built: a randomized one keeps its generator of random numbers inside
380 // it. Every tree has a move constructor
381 template <template <typename, class> class T, long Headers>
382 struct Of
383 {
384 template <typename Key, class Compare>
385 using Tree = T<Key, Compare>;
386
387 template <typename Key, class Compare = Aleph::less<Key>>
388 using Set = DynSetTree<Key, T, Compare>;
389
390 template <typename Key, typename Data, class Compare = Aleph::less<Key>>
392
393 static constexpr long headers = Headers;
394 static constexpr bool header = Headers > 0;
395 };
396
397 template <class Kind>
398 class Noexcept_Construction : public ::testing::Test {};
399
400 using Tree_Kinds = ::testing::Types<
401 Of<BinTree, 1>, Of<Avl_Tree, 1>, Of<Avl_Tree_Rk, 1>,
402 Of<Rb_Tree, 1>, Of<Rb_Tree_Rk, 1>, Of<HtdRbTree, 3>,
403 Of<HtdRbTreeRk, 3>, Of<TdRbTree, 2>, Of<TdRbTreeRk, 2>,
404 Of<Splay_Tree, 1>, Of<Splay_Tree_Rk, 0>,
405 Of<Treap, 1>, Of<Treap_Rk, 1>, Of<Rand_Tree, 0>>;
406 TYPED_TEST_SUITE(Noexcept_Construction, Tree_Kinds);
407
408 template <class Tree>
409 constexpr bool nothrow_swap = noexcept(std::declval<Tree &>().swap(std::declval<Tree &>()));
410} // namespace
411
412// With a key and a comparison that cannot throw, a tree is built, moved
413// and swapped without throwing
414TYPED_TEST(Noexcept_Construction, IsNoexceptWithTypesThatDoNotThrow)
415{
416 using Tree = typename TypeParam::template Tree<int, Aleph::less<int>>;
417 EXPECT_TRUE(std::is_nothrow_default_constructible_v<Tree>);
418 EXPECT_TRUE(nothrow_swap<Tree>);
419 EXPECT_TRUE(std::is_nothrow_move_constructible_v<Tree>);
420}
421
422// No tree is copied: a tree does not own its nodes, and a copy would hold
423// the same ones. Four trees declared neither a copy nor a move (Avl_Tree,
424// Avl_Tree_Rk, Splay_Tree and Splay_Tree_Rk): the compiler wrote a copy
425// for them, which std::move() of a tree took, and which left two trees
426// with the same nodes
427TYPED_TEST(Noexcept_Construction, ATreeIsMovedAndNotCopied)
428{
429 using Tree = typename TypeParam::template Tree<int, Aleph::less<int>>;
430 EXPECT_TRUE(std::is_move_constructible_v<Tree>);
431 EXPECT_FALSE(std::is_copy_constructible_v<Tree>);
432 EXPECT_FALSE(std::is_copy_assignable_v<Tree>);
433}
434
435// A key whose default construction may throw makes the constructions that
436// build the header nodes of a tree potentially throwing, but not its
437// swap, nor its move, which takes the keys of the header nodes of the
438// other tree, if moving a key cannot throw. With a key whose move may
439// throw too, the move builds them by default, and may throw. A tree
440// without header nodes builds no key
441TYPED_TEST(Noexcept_Construction, FollowsTheDefaultConstructionOfTheKey)
442{
443 using Key = Key_Default_Throws;
444 using Tree = typename TypeParam::template Tree<Key, Aleph::less<Key>>;
445 EXPECT_EQ(std::is_nothrow_default_constructible_v<Tree>, not TypeParam::header);
446 EXPECT_TRUE(nothrow_swap<Tree>);
447 EXPECT_TRUE(std::is_nothrow_move_constructible_v<Tree>);
448
449 using Worse = Key_That_May_Always_Throw;
450 using Tree_Of_Worse = typename TypeParam::template Tree<Worse, Aleph::less<Worse>>;
451 EXPECT_EQ(std::is_nothrow_default_constructible_v<Tree_Of_Worse>, not TypeParam::header);
452 EXPECT_TRUE(nothrow_swap<Tree_Of_Worse>);
453 EXPECT_EQ(std::is_nothrow_move_constructible_v<Tree_Of_Worse>, not TypeParam::header);
454
455 // and a key built by default without throwing is built so, whatever
456 // its move does
457 using Plain = Key_Built_By_Default;
458 using Tree_Of_Plain = typename TypeParam::template Tree<Plain, Aleph::less<Plain>>;
459 EXPECT_TRUE(std::is_nothrow_default_constructible_v<Tree_Of_Plain>);
460 EXPECT_TRUE(std::is_nothrow_move_constructible_v<Tree_Of_Plain>);
461}
462
463// The move of a tree builds no key that it can take from the other tree.
464// It builds one for each header node: by default, as an empty tree does,
465// when that cannot throw; else by moving that of the same header node of
466// the other tree, when that cannot throw; else by default. It copies none
467TYPED_TEST(Noexcept_Construction, TheMoveOfATreeBuildsNoKeyThatItCanTake)
468{
469 const long headers = TypeParam::headers;
470 {
471 using Key = Key_Built_By_Default;
472 using Tree = typename TypeParam::template Tree<Key, Aleph::less<Key>>;
473 const Key_Counts built = built_by_the_move_of_an_empty<Tree>();
474 EXPECT_EQ(built.defaults, headers);
475 EXPECT_EQ(built.moves, 0);
476 EXPECT_EQ(built.copies, 0);
477 }
478 {
479 using Key = Key_Taken;
480 using Tree = typename TypeParam::template Tree<Key, Aleph::less<Key>>;
481 const Key_Counts built = built_by_the_move_of_an_empty<Tree>();
482 EXPECT_EQ(built.defaults, 0);
483 EXPECT_EQ(built.moves, headers);
484 EXPECT_EQ(built.copies, 0);
485 }
486 {
487 using Key = Key_That_May_Always_Throw;
488 using Tree = typename TypeParam::template Tree<Key, Aleph::less<Key>>;
489 const Key_Counts built = built_by_the_move_of_an_empty<Tree>();
490 EXPECT_EQ(built.defaults, headers);
491 EXPECT_EQ(built.moves, 0);
492 EXPECT_EQ(built.copies, 0);
493 }
494}
495
496// A comparison whose copy, move or swap may throw makes the constructions,
497// the move and the swap of a tree potentially throwing
498TYPED_TEST(Noexcept_Construction, FollowsTheCopyMoveAndSwapOfTheComparison)
499{
500 using Tree = typename TypeParam::template Tree<int, Less_Copy_Throws>;
501 EXPECT_FALSE(std::is_nothrow_default_constructible_v<Tree>);
502 EXPECT_FALSE(nothrow_swap<Tree>);
503 EXPECT_FALSE(std::is_nothrow_move_constructible_v<Tree>);
504}
505
506// The move of a tree copies the comparison, so that the tree that it
507// moves from keeps its own: it follows that copy, and neither the default
508// construction of the comparison, which it does not build, nor its move
509// or its swap, which it does not use
510TYPED_TEST(Noexcept_Construction, TheMoveOfATreeFollowsTheCopyOfTheComparisonAlone)
511{
512 using By_Default = typename TypeParam::template Tree<int, Less_Default_Throws<int>>;
513 EXPECT_FALSE(std::is_nothrow_default_constructible_v<By_Default>);
514 EXPECT_TRUE(std::is_nothrow_move_constructible_v<By_Default>);
515
516 using By_Copy = typename TypeParam::template Tree<int, Less_Copy_Alone_Throws<int>>;
517 ASSERT_TRUE(std::is_nothrow_move_constructible_v<Less_Copy_Alone_Throws<int>>);
518 EXPECT_FALSE(std::is_nothrow_move_constructible_v<By_Copy>);
519
520 // the copy from a comparison that is const, and not the one from one
521 // that is not, which the constructors that take a comparison use
522 using By_Mutable_Copy = typename TypeParam::template Tree<int, Less_Mutable_Copy_Throws<int>>;
523 EXPECT_TRUE(std::is_nothrow_move_constructible_v<By_Mutable_Copy>);
524
525 // a tree with a comparison built by default that throws, built with
526 // another one: its move builds none, and throws nothing
527 Less_Default_Throws<int> less;
528 By_Default tree(less);
529 const Failing_At failing(0);
530 EXPECT_NO_THROW(By_Default taken(std::move(tree)));
531}
532
533// What the default construction of the key throws reaches the caller,
534// instead of ending the program
535TYPED_TEST(Noexcept_Construction, LetsTheFailureOfTheKeyThrough)
536{
537 using Key = Key_Default_Throws;
538 using Tree = typename TypeParam::template Tree<Key, Aleph::less<Key>>;
539 const long failures = failures_through([] { Tree tree; (void) tree; });
540 if constexpr (TypeParam::header)
541 EXPECT_GT(failures, 0);
542 else
543 EXPECT_EQ(failures, 0);
544}
545
546// What the copy of the comparison throws reaches the caller
547TYPED_TEST(Noexcept_Construction, LetsTheFailureOfTheComparisonThrough)
548{
549 using Tree = typename TypeParam::template Tree<int, Less_Copy_Throws>;
550 const Less_Copy_Throws cmp;
551 EXPECT_GT(failures_through([&cmp] { Tree tree(cmp); (void) tree; }), 0);
552}
553
554// With keys, values and a comparison that cannot throw, a set and a map
555// are built and move without throwing, on every tree.
556// The key of the nodes of a map is a std::pair, whose default constructor
557// libstdc++ does not declare noexcept: the nodes look into it
558TYPED_TEST(Noexcept_Construction, ASetAndAMapAreNoexceptWithTypesThatDoNotThrow)
559{
560 using Set = typename TypeParam::template Set<int>;
561 using Map = typename TypeParam::template Map<int, std::string>;
562 using Map_Of_Pairs = typename TypeParam::template Map<std::string, std::pair<int, long>>;
563 EXPECT_TRUE(std::is_nothrow_default_constructible_v<Set>);
564 EXPECT_TRUE(std::is_nothrow_default_constructible_v<Map>);
565 // and so is a set built with a comparison, as the copy of that one
566 using Set_Whose_Comparison_Throws = typename TypeParam::template Set<int, Less_Copy_Throws>;
567 EXPECT_TRUE((std::is_nothrow_constructible_v<Set, const Aleph::less<int> &>));
568 EXPECT_FALSE((std::is_nothrow_constructible_v<Set_Whose_Comparison_Throws,
569 const Less_Copy_Throws &>));
570 EXPECT_TRUE(std::is_nothrow_move_constructible_v<Set>);
571 EXPECT_TRUE(std::is_nothrow_move_constructible_v<Map>);
572 EXPECT_TRUE(std::is_nothrow_move_constructible_v<Map_Of_Pairs>);
573 EXPECT_TRUE(std::is_nothrow_move_assignable_v<Set>);
574 EXPECT_TRUE(std::is_nothrow_move_assignable_v<Map>);
575}
576
577// The move of a set moves its tree, which builds no key that it can take:
578// with a key, or with a value of a map, whose default construction may
579// throw, it is noexcept on every tree, if the move of the key cannot
580// throw. With a key whose move may throw too, it is noexcept only on a
581// tree without header nodes. The move assignment builds nothing
582TYPED_TEST(Noexcept_Construction, TheMoveOfASetBuildsNoKeyThatItCanTake)
583{
584 {
585 using Key = Key_Default_Throws;
586 using Set = typename TypeParam::template Set<Key>;
587 using Map_To_It = typename TypeParam::template Map<int, Key>;
588 using Map_From_It = typename TypeParam::template Map<Key, int>;
589 EXPECT_TRUE(std::is_nothrow_move_constructible_v<Set>);
590 EXPECT_TRUE(std::is_nothrow_move_constructible_v<Map_To_It>);
591 EXPECT_TRUE(std::is_nothrow_move_constructible_v<Map_From_It>);
592 EXPECT_TRUE(std::is_nothrow_move_assignable_v<Set>);
593 EXPECT_TRUE(std::is_nothrow_move_assignable_v<Map_To_It>);
594 }
595 {
596 using Key = Key_That_May_Always_Throw;
597 using Set = typename TypeParam::template Set<Key>;
598 using Map_To_It = typename TypeParam::template Map<int, Key>;
599 using Map_From_It = typename TypeParam::template Map<Key, int>;
600 const bool nothrow = not TypeParam::header;
601 EXPECT_EQ(std::is_nothrow_move_constructible_v<Set>, nothrow);
602 EXPECT_EQ(std::is_nothrow_move_constructible_v<Map_To_It>, nothrow);
603 EXPECT_EQ(std::is_nothrow_move_constructible_v<Map_From_It>, nothrow);
604 EXPECT_TRUE(std::is_nothrow_move_assignable_v<Set>);
605 EXPECT_TRUE(std::is_nothrow_move_assignable_v<Map_To_It>);
606 }
607
608 // what the move of a set with elements builds: a key for each header
609 // node of its tree, and no other
610 const long headers = TypeParam::headers;
611 Key_Counts built = built_by_the_move_of_a_set_of_five<
612 typename TypeParam::template Set<Key_Built_By_Default>, Key_Built_By_Default>();
613 EXPECT_EQ(built.defaults, headers);
614 EXPECT_EQ(built.moves, 0);
615 EXPECT_EQ(built.copies, 0);
616 built = built_by_the_move_of_a_set_of_five<
617 typename TypeParam::template Set<Key_Taken>, Key_Taken>();
618 EXPECT_EQ(built.defaults, 0);
619 EXPECT_EQ(built.moves, headers);
620 EXPECT_EQ(built.copies, 0);
621 built = built_by_the_move_of_a_set_of_five<
622 typename TypeParam::template Set<Key_That_May_Always_Throw>, Key_That_May_Always_Throw>();
623 EXPECT_EQ(built.defaults, headers);
624 EXPECT_EQ(built.moves, 0);
625 EXPECT_EQ(built.copies, 0);
626
627 // and that of a map, whose nodes hold a pair of a key and a value
628 using Map = typename TypeParam::template Map<int, Key_Taken>;
629 Map map;
630 for (int i = 0; i < 5; ++i)
631 (void) map.insert(i, Key_Taken(10 * i));
632 built = counted_in([&map] { Map taken(std::move(map)); EXPECT_EQ(taken.size(), 5u); });
633 EXPECT_EQ(built.defaults, 0);
634 EXPECT_EQ(built.moves, headers);
635 EXPECT_EQ(built.copies, 0);
636}
637
638// The move of a set builds no comparison by default: the tree that takes
639// the nodes copies that of the other tree. It built one, for the empty
640// tree of the set that it moved from, and what that construction threw
641// reached the caller, or ended the program
642TYPED_TEST(Noexcept_Construction, TheMoveOfASetBuildsNoComparisonByDefault)
643{
644 using Set = typename TypeParam::template Set<int, Less_Default_Throws<int>>;
645 EXPECT_FALSE(std::is_nothrow_default_constructible_v<Set>);
646 EXPECT_TRUE(std::is_nothrow_move_constructible_v<Set>);
647 EXPECT_TRUE(std::is_nothrow_move_assignable_v<Set>);
648
649 Set set;
650 for (int i = 0; i < 5; ++i)
651 (void) set.insert(i);
652 {
653 const Failing_At failing(0);
654 Set taken(std::move(set));
655 EXPECT_EQ(taken.size(), 5u);
656 for (int i = 0; i < 5; ++i)
657 EXPECT_NE(taken.search(i), nullptr) << i;
658 }
659 // the set that was moved from takes elements again
660 EXPECT_TRUE(set.is_empty());
661 for (int i = 0; i < 5; ++i)
662 (void) set.insert(i);
663 EXPECT_EQ(set.size(), 5u);
664}
665
666// The tree that takes the nodes copies the comparison of the other tree,
667// so that the set that is moved from keeps its own: the move of a set
668// follows that copy, on every tree. What the copy throws reaches the
669// caller, and the set is left as it was
670TYPED_TEST(Noexcept_Construction, TheMoveOfASetFollowsTheCopyOfTheComparison)
671{
672 using Less = Less_Copy_Alone_Throws<int>;
673 using Set = typename TypeParam::template Set<int, Less>;
674 ASSERT_TRUE(std::is_nothrow_default_constructible_v<Less>);
675 ASSERT_TRUE(std::is_nothrow_swappable_v<Less>);
676 EXPECT_FALSE(std::is_nothrow_default_constructible_v<Set>);
677 EXPECT_FALSE(std::is_nothrow_move_constructible_v<Set>);
678 EXPECT_TRUE(std::is_nothrow_move_assignable_v<Set>);
679
680 Set set;
681 for (int i = 0; i < 5; ++i)
682 (void) set.insert(i);
683 {
684 const Failing_At failing(0);
685 EXPECT_THROW(Set taken(std::move(set)), Asked_Failure);
686 }
687 EXPECT_EQ(set.size(), 5u);
688 for (int i = 0; i < 5; ++i)
689 EXPECT_NE(set.search(i), nullptr) << i;
690}
691
692// What the default construction of the comparison throws reaches the
693// caller when a set or a map is built by default, and when a class that
694// inherits the constructors of a set is: GCC and Clang do not count a
695// default argument in the noexcept of such an implicit constructor, so the
696// set builds its comparison in a default constructor of its own
697TYPED_TEST(Noexcept_Construction, ASetBuiltByDefaultLetsTheFailureOfTheComparisonThrough)
698{
699 using Set = typename TypeParam::template Set<int, Less_Default_Throws<int>>;
700 using Map = typename TypeParam::template Map<int, int, Less_Default_Throws<int>>;
701 struct Inheriting : Set
702 {
703 using Set::Set;
704 };
705 EXPECT_FALSE(std::is_nothrow_default_constructible_v<Inheriting>);
706 EXPECT_FALSE(std::is_nothrow_default_constructible_v<Map>);
707
708 const Failing_At failing(0);
709 EXPECT_THROW(Set set, Asked_Failure);
710 EXPECT_THROW(Inheriting inheriting, Asked_Failure);
711 EXPECT_THROW(Map map, Asked_Failure);
712}
713
714// A tree built by default with a comparison whose default construction
715// throws lets what it throws through. Most trees inherit their
716// constructors, and those took the comparison as a default argument,
717// which GCC and Clang do not count in the noexcept of the implicit default
718// constructor: the program ended
719TYPED_TEST(Noexcept_Construction, ATreeBuiltByDefaultLetsTheFailureOfTheComparisonThrough)
720{
721 expect_that_the_default_construction_lets_the_comparison_throw<
722 typename TypeParam::template Tree<int, Less_Default_Throws<int>>>();
723}
724
725// A tree that takes its comparison by value copies it from one that is not
726// const: its noexcept follows that copy, and what the copy throws reaches
727// the caller. One that takes it by a const reference copies from that
728TYPED_TEST(Noexcept_Construction, ATreeBuiltFromAComparisonLetsTheFailureOfItsCopyThrough)
729{
730 expect_that_the_copy_of_the_comparison_lets_it_throw<
731 typename TypeParam::template Tree<int, Less_Mutable_Copy_Throws<int>>,
732 Less_Mutable_Copy_Throws<int>>();
733}
734
735// What a tree whose nodes have a virtual destructor does with the
736// comparison: they share the constructors of the others, but for the ones
737// that inherit those of HtdRbTree and HtdRbTreeRk
738TEST(Noexcept_Construction_Trees, TheTreesOfVirtualNodesLetTheFailureOfTheComparisonThrough)
739{
740 using L = Less_Default_Throws<int>;
741 expect_that_the_default_construction_lets_the_comparison_throw<BinTreeVtl<int, L>>();
742 expect_that_the_default_construction_lets_the_comparison_throw<Avl_Tree_Vtl<int, L>>();
743 expect_that_the_default_construction_lets_the_comparison_throw<Avl_Tree_Rk_Vtl<int, L>>();
744 expect_that_the_default_construction_lets_the_comparison_throw<Rb_Tree_Vtl<int, L>>();
745 expect_that_the_default_construction_lets_the_comparison_throw<Rb_Tree_Rk_Vtl<int, L>>();
746 expect_that_the_default_construction_lets_the_comparison_throw<Splay_Tree_Vtl<int, L>>();
747 expect_that_the_default_construction_lets_the_comparison_throw<HtdRbTreeVtl<int, L>>();
748 expect_that_the_default_construction_lets_the_comparison_throw<HtdRbTreeRkVtl<int, L>>();
749
750 using M = Less_Mutable_Copy_Throws<int>;
751 expect_that_the_copy_of_the_comparison_lets_it_throw<HtdRbTreeVtl<int, M>, M>();
752 expect_that_the_copy_of_the_comparison_lets_it_throw<HtdRbTreeRkVtl<int, M>, M>();
753}
754
755// With a key whose default construction and whose move may throw, the
756// move of a set builds by default the key of each header node of its
757// tree. What that construction throws reaches the caller, instead of
758// ending the program, and the set is left as it was: the header nodes are
759// built before anything is taken. There is a failure to try for each
760// header node, and no other
761TYPED_TEST(Noexcept_Construction, AMoveOfASetThatThrowsLeavesItAsItWas)
762{
763 using Key = Key_That_May_Always_Throw;
764 using Set = typename TypeParam::template Set<Key>;
765 Set set;
766 for (int i = 0; i < 5; ++i)
767 (void) set.insert(Key(i));
768
769 long failures = 0;
770 for (bool moved = false; not moved; )
771 {
772 {
773 const Failing_At failing(failures);
774 try
775 {
776 Set taken(std::move(set));
777 moved = true;
778 EXPECT_EQ(taken.size(), 5u);
779 EXPECT_TRUE(set.is_empty());
780 }
781 catch (const Asked_Failure &)
782 {
783 ++failures;
784 }
785 }
786 if (not moved)
787 {
788 ASSERT_EQ(set.size(), 5u);
789 for (int i = 0; i < 5; ++i)
790 ASSERT_NE(set.search(Key(i)), nullptr) << i;
791 }
792 }
793
794 EXPECT_EQ(failures, TypeParam::headers);
795}
796
797// And so does a map, whose nodes hold a pair of a key and a value
798TYPED_TEST(Noexcept_Construction, AMoveOfAMapThatThrowsLeavesItAsItWas)
799{
800 using Value = Key_That_May_Always_Throw;
801 using Map = typename TypeParam::template Map<int, Value>;
802 Map map;
803 for (int i = 0; i < 5; ++i)
804 (void) map.insert(i, Value(10 * i));
805
806 // the search of a map on a splay tree builds a value by default: the
807 // map is looked at once the failures are over
808 long failures = 0;
809 for (bool moved = false; not moved; )
810 {
811 {
812 const Failing_At failing(failures);
813 try
814 {
815 Map taken(std::move(map));
816 moved = true;
817 EXPECT_EQ(taken.size(), 5u);
818 EXPECT_TRUE(map.is_empty());
819 }
820 catch (const Asked_Failure &)
821 {
822 ++failures;
823 }
824 }
825 if (not moved)
826 {
827 ASSERT_EQ(map.size(), 5u);
828 for (int i = 0; i < 5; ++i)
829 {
830 const auto * pair = map.search(i);
831 ASSERT_NE(pair, nullptr) << i;
832 ASSERT_EQ(pair->second.value, 10 * i);
833 }
834 }
835 }
836
837 EXPECT_EQ(failures, TypeParam::headers);
838}
839
840// With a key whose move cannot throw, nothing that the move of a set or of
841// a map does may throw: with every operation of the key failing, it takes
842// the elements
843TYPED_TEST(Noexcept_Construction, AMoveOfASetThatTakesItsKeysCannotFail)
844{
845 using Key = Key_Default_Throws;
846 using Set = typename TypeParam::template Set<Key>;
847 using Map = typename TypeParam::template Map<int, Key>;
848 Set set;
849 Map map;
850 for (int i = 0; i < 5; ++i)
851 {
852 (void) set.insert(Key(i));
853 (void) map.insert(i, Key(10 * i));
854 }
855
856 const Failing_At failing(0);
857 Set taken_set(std::move(set));
858 Map taken_map(std::move(map));
859 EXPECT_EQ(taken_set.size(), 5u);
860 EXPECT_EQ(taken_map.size(), 5u);
861 EXPECT_TRUE(set.is_empty());
862 EXPECT_TRUE(map.is_empty());
863}
864
865// The node of a tree says whether the default construction of its key may
866// throw; for a std::pair, the key of the nodes of a map, by its members
867TEST(Noexcept_Construction_Nodes, TheKeyOfAMapIsSeenInItsMembers)
868{
869 using Key = Key_Default_Throws;
870 EXPECT_TRUE(std::is_nothrow_default_constructible_v<AvlNode<int>>);
871 EXPECT_FALSE(std::is_nothrow_default_constructible_v<AvlNode<Key>>);
872 EXPECT_TRUE((std::is_nothrow_default_constructible_v<AvlNode<std::pair<int, std::string>>>));
873 EXPECT_TRUE((std::is_nothrow_default_constructible_v<
874 AvlNode<std::pair<int, std::pair<long, std::string>>>>));
875 EXPECT_FALSE((std::is_nothrow_default_constructible_v<AvlNode<std::pair<int, Key>>>));
876 EXPECT_FALSE((std::is_nothrow_default_constructible_v<AvlNode<std::pair<Key, int>>>));
877 EXPECT_FALSE((std::is_nothrow_default_constructible_v<
878 AvlNode<std::pair<int, std::pair<long, Key>>>>));
879 // so does the constructor that takes the control data of the node
880 EXPECT_TRUE((std::is_nothrow_constructible_v<AvlNode<std::pair<int, std::string>>,
881 const AvlNode_Data &>));
882 EXPECT_FALSE((std::is_nothrow_constructible_v<AvlNode<std::pair<int, Key>>,
883 const AvlNode_Data &>));
884 // those of the trees that keep counters, and of the randomized ones
885 EXPECT_TRUE((std::is_nothrow_default_constructible_v<BinNodeXt<std::pair<int, int>>>));
886 EXPECT_TRUE((std::is_nothrow_default_constructible_v<TreapNode<std::pair<int, int>>>));
887 EXPECT_FALSE((std::is_nothrow_default_constructible_v<TreapNode<std::pair<int, Key>>>));
888}
889
890// The tree without header nodes builds its comparison in a default
891// constructor of its own, as a set does: what that construction throws
892// reaches the caller, though the tree inherits its constructors
893TEST(Noexcept_Construction_Trees, TheTreeWithoutHeaderNodesLetsTheFailureOfItsComparisonThrough)
894{
896 EXPECT_FALSE(std::is_nothrow_default_constructible_v<Tree>);
897 EXPECT_TRUE((std::is_nothrow_constructible_v<Tree, Less_Default_Throws<int>>));
898
899 const Failing_At failing(0);
900 EXPECT_THROW(Tree tree, Asked_Failure);
901}
902
903// A constructor that takes its comparison by value and copies it copies
904// from a comparison that is not const: its noexcept follows that copy, and
905// not the one from a const comparison, and what it throws reaches the
906// caller
907TEST(Noexcept_Construction_Trees, TheCopyOfAComparisonTakenByValueIsFromOneThatIsNotConst)
908{
909 using Less = Less_Mutable_Copy_Throws<int>;
910 ASSERT_TRUE(std::is_nothrow_copy_constructible_v<Less>);
911 ASSERT_FALSE((std::is_nothrow_constructible_v<Less, Less &>));
912 EXPECT_FALSE((std::is_nothrow_constructible_v<Splay_Tree_Rk<int, Less>, Less>));
913 EXPECT_FALSE((std::is_nothrow_constructible_v<Dft_Pair_Cmp<int, std::string, Less>, Less>));
914 EXPECT_TRUE((std::is_nothrow_constructible_v<Splay_Tree_Rk<int>, Aleph::less<int>>));
915
916 const Failing_At failing(0);
917 EXPECT_THROW((Splay_Tree_Rk<int, Less>(Less())), Asked_Failure);
918 EXPECT_THROW((Dft_Pair_Cmp<int, std::string, Less>(Less())), Asked_Failure);
919}
920
921// The comparison of the pairs of a map is built as that of its keys, and
922// in a default constructor of its own: a class that holds one lets what
923// the construction of the comparison of the keys throws through
924TEST(Noexcept_Construction_Maps, TheComparisonOfThePairsFollowsThatOfTheKeys)
925{
926 struct Holding
927 {
929 };
930 EXPECT_FALSE(std::is_nothrow_default_constructible_v<Holding>);
931 {
932 const Failing_At failing(0);
933 EXPECT_THROW(Holding holding, Asked_Failure);
934 }
935 EXPECT_TRUE((std::is_nothrow_constructible_v<
936 Dft_Pair_Cmp<int, std::string, Aleph::less<int>>, Aleph::less<int>>));
937 EXPECT_FALSE((std::is_nothrow_constructible_v<
938 Dft_Pair_Cmp<int, std::string, Less_Copy_Throws>, const Less_Copy_Throws &>));
939 // it copies the comparison that it takes, though it takes it by a move
940 using Less = Less_Copy_Alone_Throws<int>;
941 EXPECT_FALSE((std::is_nothrow_constructible_v<Dft_Pair_Cmp<int, std::string, Less>, Less>));
942 {
943 const Failing_At failing(0);
944 EXPECT_THROW((Dft_Pair_Cmp<int, std::string, Less>(Less())), Asked_Failure);
945 }
946
947 EXPECT_TRUE((std::is_nothrow_default_constructible_v<
948 Dft_Pair_Cmp<int, std::string, Aleph::less<int>>>));
949 EXPECT_FALSE((std::is_nothrow_default_constructible_v<
950 Dft_Pair_Cmp<int, std::string, Less_Default_Throws<int>>>));
951 EXPECT_FALSE((std::is_nothrow_default_constructible_v<
953 EXPECT_FALSE((std::is_nothrow_default_constructible_v<
954 DynMapTree<int, int, Avl_Tree, Less_Default_Throws<int>>>));
955 // the move of a map builds no comparison by default: it copies it
956 EXPECT_TRUE((std::is_nothrow_move_constructible_v<
957 DynMapTree<int, int, Avl_Tree, Less_Default_Throws<int>>>));
958 EXPECT_FALSE((std::is_nothrow_move_constructible_v<
959 DynMapTree<int, int, Avl_Tree, Less_Copy_Alone_Throws<int>>>));
960}
961
962// A map moves without throwing when its values are built by default, or
963// moved, without throwing: so do the containers that allocate nothing
964// when they are built, a list and a set or a map on a tree, a randomized
965// one too, whose generator of random numbers is inside it; and those
966// that allocate when they are built and not when they are moved, as an
967// Array, whose map said that its move may throw
968TEST(Noexcept_Construction_Maps, AMapOfContainersMovesAsTheyAreBuiltOrMoved)
969{
970 EXPECT_TRUE(std::is_nothrow_default_constructible_v<DynList<int>>);
971 EXPECT_TRUE(std::is_nothrow_default_constructible_v<DynSetTree<int>>);
972 EXPECT_TRUE((std::is_nothrow_default_constructible_v<DynMapTree<int, int>>));
973 EXPECT_TRUE((std::is_nothrow_move_constructible_v<DynMapTree<int, DynList<int>>>));
974 EXPECT_TRUE((std::is_nothrow_move_constructible_v<DynMapTree<int, DynSetTree<int>>>));
975 EXPECT_TRUE((std::is_nothrow_move_constructible_v<DynMapTree<int, DynMapTree<int, int>>>));
976
977 EXPECT_TRUE((std::is_nothrow_default_constructible_v<DynSetTree<int, Treap>>));
978 EXPECT_TRUE((std::is_nothrow_default_constructible_v<DynSetTree<int, Treap_Rk>>));
979 EXPECT_TRUE((std::is_nothrow_default_constructible_v<DynSetTree<int, Rand_Tree>>));
980 EXPECT_TRUE((std::is_nothrow_move_constructible_v<DynMapTree<int, DynSetTree<int, Treap>>>));
981 EXPECT_TRUE((std::is_nothrow_move_constructible_v<DynMapTree<int, DynSetTree<int, Rand_Tree>>>));
982
983 EXPECT_FALSE(std::is_nothrow_default_constructible_v<Array<int>>);
984 EXPECT_TRUE(std::is_nothrow_move_constructible_v<Array<int>>);
985 EXPECT_TRUE((std::is_nothrow_move_constructible_v<DynMapTree<int, Array<int>>>));
986 EXPECT_TRUE((std::is_nothrow_move_constructible_v<DynMapTree<int, DynMapTree<int, Array<int>>>>));
987}
988
989// A mapping moves its map: its move is noexcept exactly when that one is
990TEST(Noexcept_Construction_Maps, AMappingMovesAsItsMap)
991{
992 using Key = Key_Default_Throws;
993 using Worse = Key_That_May_Always_Throw;
994 EXPECT_TRUE((std::is_nothrow_move_constructible_v<AHMapping<int, std::string>>));
995 EXPECT_TRUE((std::is_nothrow_move_constructible_v<AHMapping<int, Key>>));
996 EXPECT_FALSE((std::is_nothrow_move_constructible_v<AHMapping<int, Worse>>));
997 EXPECT_TRUE((std::is_nothrow_move_assignable_v<AHMapping<int, Worse>>));
998
999 AHMapping<int, Worse> mapping;
1000 for (int i = 0; i < 5; ++i)
1001 mapping.insert(i, Worse(10 * i));
1002 {
1003 const Failing_At failing(0);
1004 EXPECT_THROW((AHMapping<int, Worse>(std::move(mapping))), Asked_Failure);
1005 }
1006 EXPECT_EQ(mapping.size(), 5u);
1007 for (int i = 0; i < 5; ++i)
1008 EXPECT_EQ(std::as_const(mapping)[i].value, 10 * i);
1009
1010 // with a value whose move cannot throw, nothing fails
1011 AHMapping<int, Key> other;
1012 for (int i = 0; i < 5; ++i)
1013 other.insert(i, Key(10 * i));
1014 const Failing_At failing(0);
1015 const AHMapping<int, Key> taken(std::move(other));
1016 EXPECT_EQ(taken.size(), 5u);
1017 EXPECT_EQ(other.size(), 0u);
1018}
1019
1020// The buckets of the open hash tables build their key
1021TEST(Noexcept_Construction_Hash, TheBucketsFollowTheDefaultConstructionOfTheKey)
1022{
1023 EXPECT_TRUE(std::is_nothrow_default_constructible_v<OLhashTable<int>::Bucket>);
1024 EXPECT_TRUE(std::is_nothrow_default_constructible_v<ODhashTable<int>::Bucket>);
1025 EXPECT_FALSE(std::is_nothrow_default_constructible_v<OLhashTable<Key_Default_Throws>::Bucket>);
1026 EXPECT_FALSE(std::is_nothrow_default_constructible_v<ODhashTable<Key_Default_Throws>::Bucket>);
1027
1028 const Failing_At failing(0);
1031 EXPECT_THROW((void) std::make_unique<OL_Bucket[]>(3), Asked_Failure);
1032 EXPECT_THROW((void) std::make_unique<OD_Bucket[]>(3), Asked_Failure);
1033}
1034
1035// The sifts of DynArrayHeap call its comparison
1036TEST(Noexcept_Construction_Heap, TheSiftsFollowTheComparison)
1037{
1038 DynArray<int> a;
1039 Aleph::less<int> nothrow_less;
1040 Less_Call_Throws throwing_less;
1041 EXPECT_TRUE(noexcept(sift_up(a, 1, 1, nothrow_less)));
1042 EXPECT_TRUE(noexcept(sift_down(a, 1, 1, nothrow_less)));
1043 EXPECT_FALSE(noexcept(sift_up(a, 1, 1, throwing_less)));
1044 EXPECT_FALSE(noexcept(sift_down(a, 1, 1, throwing_less)));
1045
1047 for (int i = 10; i > 0; --i)
1048 heap.insert(i);
1049 const Failing_At failing(0);
1050 EXPECT_THROW(heap.insert(0), Asked_Failure);
1051 EXPECT_THROW((void) heap.getMin(), Asked_Failure);
1052}
Bidirectional mapping between two types.
bool operator<(const Time &l, const Time &r)
Definition ah-time.H:143
TYPED_TEST_SUITE(ArcHeapLifecycle, ArcHeapKinds)
size_t size_t int32_t value
Definition ca-c-api.h:116
A generic key-value mapping container with inverse operation support.
Definition ah-mapping.H:70
size_t size() const noexcept
Gets the number of key-value pairs in the mapping.
Definition ah-mapping.H:235
void insert(const Key &key, const ValueType &value)
Inserts or updates a key-value pair in the mapping.
Definition ah-mapping.H:136
Simple dynamic array with automatic resizing and functional operations.
Definition tpl_array.H:141
Node for extended binary search tree.
Dynamic heap (priority queue) backed by DynArray.
T getMin()
Remove and return the top element.
T & insert(const T &key)
Insert a copy of key into the heap.
Doubly-linked list (defined in tpl_dynList.H).
Definition htlist.H:1231
Generic key-value map implemented on top of a binary search tree.
Dynamic set backed by balanced binary search trees with automatic memory management.
Open addressing hash table with double hashing collision resolution.
Definition tpl_odhash.H:193
Open addressing hash table with linear probing collision resolution.
Definition tpl_olhash.H:175
Declare TreapNode type with 80-byte pool allocation.
Definition treapNode.H:108
Data portion of an AVL tree node.
Definition avlNode.H:77
Declare AvlNode type with 40-byte pool allocation.
Definition avlNode.H:98
QuadTree - Hierarchical spatial index for 2D points.
Definition quadtree.H:126
Point * insert(Node *&r, const Point &p)
Recursive insert helper.
Definition quadtree.H:281
#define TEST(name)
int cmp(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Definition gmpfrxx.h:4196
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
bool operator==(const DynList< T > &l1, const DynList< T > &l2)
Equality operator for DynList.
void sift_down(T *ptr, const size_t l, const size_t r, Compare &cmp)
Restore the heap property by moving the element at position l downwards.
@ Value
Regular runtime payload stored as Interpreter_Value.
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:152
std::pair< First, Second > pair
Alias to std::pair kept for backwards compatibility.
Definition ahPair.H:89
T & sift_up(T *ptr, const size_t l, const size_t r, Compare &cmp)
Restore the heap property by moving the element at position r upwards.
STL namespace.
TYPED_TEST(Noexcept_Construction, IsNoexceptWithTypesThatDoNotThrow)
AVL binary search tree with nodes without a virtual destructor.
Definition tpl_avl.H:831
Default comparator for pair types in hash maps.
Definition ahDry.H:206
static int * k
Dynamic array container with automatic resizing.
AVL tree with rank (order statistics).
AVL tree implementation (height-balanced BST).
Generic unbalanced binary search tree.
Array-based dynamic binary heap.
Dynamic key-value map based on balanced binary search trees.
Dynamic set implementations based on balanced binary search trees.
Hybrid top-down/bottom-up red-black tree with rank support.
Hybrid top-down/bottom-up red-black tree implementation.
Open addressing hash table with double hashing.
Open addressing hash table with linear probing.
Randomized binary search tree.
Red-Black tree with rank (order statistics).
Red-Black tree implementation (bottom-up balancing).
Top-down splay tree with rank support.
Top-down splay tree implementation (without rank support).
Top-down Red-Black tree with rank support.
Top-down Red-Black tree implementation.
Treap with rank (order statistics).
Treap: randomized BST combining tree and heap properties.