65# include <type_traits>
68# include <gtest/gtest.h>
98 struct Asked_Failure : std::runtime_error
100 Asked_Failure() :
std::runtime_error(
"an operation of the user failed") {}
110 throw Asked_Failure();
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;
129 long failures_through(
F && f)
131 for (
long k = 0; ; ++
k)
133 const Failing_At failing(
k);
139 catch (
const Asked_Failure &)
149 template <
class Tree>
150 void expect_that_the_default_construction_lets_the_comparison_throw()
152 EXPECT_FALSE(std::is_nothrow_default_constructible_v<Tree>);
153 EXPECT_GT(failures_through([] {
Tree tree; }), 0);
159 template <
class Tree,
class Less>
160 void expect_that_the_copy_of_the_comparison_lets_it_throw()
162 if (failures_through([] {
Tree tree((
Less())); }) > 0)
164 EXPECT_FALSE((std::is_nothrow_constructible_v<Tree, Less>));
169 struct Key_Default_Throws
173 Key_Default_Throws() { maybe_fail(); }
174 Key_Default_Throws(
const int v) noexcept :
value(v) {}
176 friend bool operator < (
const Key_Default_Throws & a,
const Key_Default_Throws & b)
noexcept
178 return a.value < b.value;
181 friend bool operator == (
const Key_Default_Throws & a,
const Key_Default_Throws & b)
noexcept
183 return a.value == b.value;
195 Key_Counts key_counts;
199 Key_Counts counted_in(
F && f)
201 const Key_Counts before = key_counts;
203 return {key_counts.defaults - before.defaults, key_counts.copies - before.copies,
204 key_counts.moves - before.moves};
208 template <
class Tree>
209 Key_Counts built_by_the_move_of_an_empty()
212 return counted_in([&tree] {
Tree taken(std::move(tree)); (void) taken; });
216 template <
class Set,
class Key>
217 Key_Counts built_by_the_move_of_a_set_of_five()
220 for (
int i = 0; i < 5; ++i)
221 (
void) set.
insert(Key(i));
222 return counted_in([&set]
224 Set taken(std::move(set));
225 EXPECT_EQ(taken.size(), 5u);
226 EXPECT_TRUE(set.is_empty());
234 template <
bool Nothrow_Default,
bool Nothrow_Move>
239 Counted_Key() noexcept(Nothrow_Default)
241 ++key_counts.defaults;
242 if constexpr (not Nothrow_Default)
246 Counted_Key(
const int v) noexcept :
value(v) {}
254 Counted_Key(Counted_Key &&
k)
noexcept(Nothrow_Move) :
value(
k.
value)
257 if constexpr (not Nothrow_Move)
261 Counted_Key & operator = (
const Counted_Key &
k)
268 Counted_Key & operator = (Counted_Key &&
k)
noexcept(Nothrow_Move)
270 if constexpr (not Nothrow_Move)
276 friend bool operator < (
const Counted_Key & a,
const Counted_Key & b)
noexcept
278 return a.value < b.value;
281 friend bool operator == (
const Counted_Key & a,
const Counted_Key & b)
noexcept
283 return a.value == b.value;
289 using Key_Built_By_Default = Counted_Key<true, false>;
293 using Key_Taken = Counted_Key<false, true>;
297 using Key_That_May_Always_Throw = Counted_Key<false, false>;
301 struct Less_Copy_Throws
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(); }
307 Less_Copy_Throws & operator = (
const Less_Copy_Throws &)
313 Less_Copy_Throws & operator = (Less_Copy_Throws &&)
319 bool operator () (
const int a,
const int b)
const noexcept {
return a < b; }
324 template <
typename Key>
325 struct Less_Default_Throws
327 Less_Default_Throws() { maybe_fail(); }
329 bool operator () (
const Key & a,
const Key & b)
const noexcept {
return a < b; }
334 template <
typename Key>
335 struct Less_Copy_Alone_Throws
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;
341 Less_Copy_Alone_Throws & operator = (const Less_Copy_Alone_Throws &)
347 Less_Copy_Alone_Throws & operator = (Less_Copy_Alone_Throws &&) noexcept = default;
349 bool operator () (const Key & a, const Key & b) const noexcept {
return a < b; }
354 template <
typename Key>
355 struct Less_Mutable_Copy_Throws
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;
364 bool operator () (const Key & a, const Key & b) const noexcept {
return a < b; }
368 struct Less_Call_Throws
370 bool operator () (
const int a,
const int b)
const
381 template <
template <
typename,
class>
class T,
long Headers>
384 template <
typename Key,
class Compare>
387 template <
typename Key,
class Compare = Aleph::less<Key>>
390 template <
typename Key,
typename Data,
class Compare = Aleph::less<Key>>
393 static constexpr long headers = Headers;
394 static constexpr bool header = Headers > 0;
397 template <
class Kind>
398 class Noexcept_Construction :
public ::testing::Test {};
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>>;
408 template <
class Tree>
409 constexpr bool nothrow_swap =
noexcept(std::declval<Tree &>().swap(std::declval<Tree &>()));
414TYPED_TEST(Noexcept_Construction, IsNoexceptWithTypesThatDoNotThrow)
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>);
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>);
441TYPED_TEST(Noexcept_Construction, FollowsTheDefaultConstructionOfTheKey)
443 using Key = Key_Default_Throws;
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>);
449 using Worse = Key_That_May_Always_Throw;
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);
457 using Plain = Key_Built_By_Default;
459 EXPECT_TRUE(std::is_nothrow_default_constructible_v<Tree_Of_Plain>);
460 EXPECT_TRUE(std::is_nothrow_move_constructible_v<Tree_Of_Plain>);
467TYPED_TEST(Noexcept_Construction, TheMoveOfATreeBuildsNoKeyThatItCanTake)
469 const long headers = TypeParam::headers;
471 using Key = Key_Built_By_Default;
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);
479 using Key = Key_Taken;
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);
487 using Key = Key_That_May_Always_Throw;
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);
498TYPED_TEST(Noexcept_Construction, FollowsTheCopyMoveAndSwapOfTheComparison)
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>);
510TYPED_TEST(Noexcept_Construction, TheMoveOfATreeFollowsTheCopyOfTheComparisonAlone)
513 EXPECT_FALSE(std::is_nothrow_default_constructible_v<By_Default>);
514 EXPECT_TRUE(std::is_nothrow_move_constructible_v<By_Default>);
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>);
523 EXPECT_TRUE(std::is_nothrow_move_constructible_v<By_Mutable_Copy>);
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)));
535TYPED_TEST(Noexcept_Construction, LetsTheFailureOfTheKeyThrough)
537 using Key = Key_Default_Throws;
539 const long failures = failures_through([] {
Tree tree; (void) tree; });
540 if constexpr (TypeParam::header)
541 EXPECT_GT(failures, 0);
543 EXPECT_EQ(failures, 0);
547TYPED_TEST(Noexcept_Construction, LetsTheFailureOfTheComparisonThrough)
550 const Less_Copy_Throws
cmp;
551 EXPECT_GT(failures_through([&
cmp] {
Tree tree(
cmp); (void) tree; }), 0);
558TYPED_TEST(Noexcept_Construction, ASetAndAMapAreNoexceptWithTypesThatDoNotThrow)
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>);
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>);
582TYPED_TEST(Noexcept_Construction, TheMoveOfASetBuildsNoKeyThatItCanTake)
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>);
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>);
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);
628 using Map =
typename TypeParam::template Map<int, Key_Taken>;
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);
642TYPED_TEST(Noexcept_Construction, TheMoveOfASetBuildsNoComparisonByDefault)
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>);
650 for (
int i = 0; i < 5; ++i)
651 (
void) set.insert(i);
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;
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);
670TYPED_TEST(Noexcept_Construction, TheMoveOfASetFollowsTheCopyOfTheComparison)
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>);
681 for (
int i = 0; i < 5; ++i)
682 (
void) set.insert(i);
684 const Failing_At failing(0);
685 EXPECT_THROW(Set taken(std::move(set)), Asked_Failure);
687 EXPECT_EQ(set.size(), 5u);
688 for (
int i = 0; i < 5; ++i)
689 EXPECT_NE(set.search(i),
nullptr) << i;
697TYPED_TEST(Noexcept_Construction, ASetBuiltByDefaultLetsTheFailureOfTheComparisonThrough)
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
705 EXPECT_FALSE(std::is_nothrow_default_constructible_v<Inheriting>);
706 EXPECT_FALSE(std::is_nothrow_default_constructible_v<Map>);
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);
719TYPED_TEST(Noexcept_Construction, ATreeBuiltByDefaultLetsTheFailureOfTheComparisonThrough)
721 expect_that_the_default_construction_lets_the_comparison_throw<
728TYPED_TEST(Noexcept_Construction, ATreeBuiltFromAComparisonLetsTheFailureOfItsCopyThrough)
730 expect_that_the_copy_of_the_comparison_lets_it_throw<
732 Less_Mutable_Copy_Throws<int>>();
738TEST(Noexcept_Construction_Trees, TheTreesOfVirtualNodesLetTheFailureOfTheComparisonThrough)
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>>();
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>();
761TYPED_TEST(Noexcept_Construction, AMoveOfASetThatThrowsLeavesItAsItWas)
763 using Key = Key_That_May_Always_Throw;
764 using Set =
typename TypeParam::template Set<Key>;
766 for (
int i = 0; i < 5; ++i)
767 (
void) set.
insert(Key(i));
770 for (
bool moved =
false; not moved; )
773 const Failing_At failing(failures);
776 Set taken(std::move(set));
778 EXPECT_EQ(taken.size(), 5u);
779 EXPECT_TRUE(set.is_empty());
781 catch (
const Asked_Failure &)
788 ASSERT_EQ(set.size(), 5u);
789 for (
int i = 0; i < 5; ++i)
790 ASSERT_NE(set.search(Key(i)),
nullptr) << i;
794 EXPECT_EQ(failures, TypeParam::headers);
798TYPED_TEST(Noexcept_Construction, AMoveOfAMapThatThrowsLeavesItAsItWas)
800 using Value = Key_That_May_Always_Throw;
801 using Map =
typename TypeParam::template Map<int, Value>;
803 for (
int i = 0; i < 5; ++i)
804 (
void) map.insert(i,
Value(10 * i));
809 for (
bool moved =
false; not moved; )
812 const Failing_At failing(failures);
815 Map taken(std::move(map));
817 EXPECT_EQ(taken.size(), 5u);
818 EXPECT_TRUE(map.is_empty());
820 catch (
const Asked_Failure &)
827 ASSERT_EQ(map.size(), 5u);
828 for (
int i = 0; i < 5; ++i)
830 const auto *
pair = map.search(i);
831 ASSERT_NE(
pair,
nullptr) << i;
832 ASSERT_EQ(
pair->second.value, 10 * i);
837 EXPECT_EQ(failures, TypeParam::headers);
843TYPED_TEST(Noexcept_Construction, AMoveOfASetThatTakesItsKeysCannotFail)
845 using Key = Key_Default_Throws;
846 using Set =
typename TypeParam::template Set<Key>;
847 using Map =
typename TypeParam::template Map<int, Key>;
850 for (
int i = 0; i < 5; ++i)
852 (void) set.insert(Key(i));
853 (void) map.insert(i, Key(10 * i));
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());
867TEST(Noexcept_Construction_Nodes, TheKeyOfAMapIsSeenInItsMembers)
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>>>>));
880 EXPECT_TRUE((std::is_nothrow_constructible_v<
AvlNode<std::pair<int, std::string>>,
882 EXPECT_FALSE((std::is_nothrow_constructible_v<
AvlNode<std::pair<int, Key>>,
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>>>));
893TEST(Noexcept_Construction_Trees, TheTreeWithoutHeaderNodesLetsTheFailureOfItsComparisonThrough)
896 EXPECT_FALSE(std::is_nothrow_default_constructible_v<Tree>);
897 EXPECT_TRUE((std::is_nothrow_constructible_v<
Tree, Less_Default_Throws<int>>));
899 const Failing_At failing(0);
900 EXPECT_THROW(
Tree tree, Asked_Failure);
907TEST(Noexcept_Construction_Trees, TheCopyOfAComparisonTakenByValueIsFromOneThatIsNotConst)
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 &>));
916 const Failing_At failing(0);
924TEST(Noexcept_Construction_Maps, TheComparisonOfThePairsFollowsThatOfTheKeys)
930 EXPECT_FALSE(std::is_nothrow_default_constructible_v<Holding>);
932 const Failing_At failing(0);
933 EXPECT_THROW(Holding holding, Asked_Failure);
935 EXPECT_TRUE((std::is_nothrow_constructible_v<
937 EXPECT_FALSE((std::is_nothrow_constructible_v<
940 using Less = Less_Copy_Alone_Throws<int>;
943 const Failing_At failing(0);
947 EXPECT_TRUE((std::is_nothrow_default_constructible_v<
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<
956 EXPECT_TRUE((std::is_nothrow_move_constructible_v<
958 EXPECT_FALSE((std::is_nothrow_move_constructible_v<
968TEST(Noexcept_Construction_Maps, AMapOfContainersMovesAsTheyAreBuiltOrMoved)
970 EXPECT_TRUE(std::is_nothrow_default_constructible_v<
DynList<int>>);
983 EXPECT_FALSE(std::is_nothrow_default_constructible_v<
Array<int>>);
984 EXPECT_TRUE(std::is_nothrow_move_constructible_v<
Array<int>>);
990TEST(Noexcept_Construction_Maps, AMappingMovesAsItsMap)
992 using Key = Key_Default_Throws;
993 using Worse = Key_That_May_Always_Throw;
1000 for (
int i = 0; i < 5; ++i)
1001 mapping.
insert(i, Worse(10 * i));
1003 const Failing_At failing(0);
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);
1012 for (
int i = 0; i < 5; ++i)
1013 other.
insert(i, Key(10 * i));
1014 const Failing_At failing(0);
1016 EXPECT_EQ(taken.
size(), 5u);
1017 EXPECT_EQ(other.
size(), 0u);
1021TEST(Noexcept_Construction_Hash, TheBucketsFollowTheDefaultConstructionOfTheKey)
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);
1036TEST(Noexcept_Construction_Heap, TheSiftsFollowTheComparison)
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)));
1047 for (
int i = 10; i > 0; --i)
1049 const Failing_At failing(0);
1050 EXPECT_THROW(heap.
insert(0), Asked_Failure);
1051 EXPECT_THROW((
void) heap.
getMin(), Asked_Failure);
Bidirectional mapping between two types.
bool operator<(const Time &l, const Time &r)
TYPED_TEST_SUITE(ArcHeapLifecycle, ArcHeapKinds)
size_t size_t int32_t value
A generic key-value mapping container with inverse operation support.
size_t size() const noexcept
Gets the number of key-value pairs in the mapping.
void insert(const Key &key, const ValueType &value)
Inserts or updates a key-value pair in the mapping.
Simple dynamic array with automatic resizing and functional operations.
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).
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.
Open addressing hash table with linear probing collision resolution.
Declare TreapNode type with 80-byte pool allocation.
Data portion of an AVL tree node.
Declare AvlNode type with 40-byte pool allocation.
QuadTree - Hierarchical spatial index for 2D points.
Point * insert(Node *&r, const Point &p)
Recursive insert helper.
int cmp(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
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
std::pair< First, Second > pair
Alias to std::pair kept for backwards compatibility.
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.
TYPED_TEST(Noexcept_Construction, IsNoexceptWithTypesThatDoNotThrow)
AVL binary search tree with nodes without a virtual destructor.
Default comparator for pair types in hash maps.
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.