Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ah_concepts_header_test.cc
Go to the documentation of this file.
1#include <ah-concepts.H>
2
3#include <gtest/gtest.h>
4
5// Regression test for aleph-concepts.md §2.1: ah-concepts.H must compile
6// when included first, on its own, without relying on another header
7// (htlist.H, tpl_array.H, ...) having pulled in <cstddef> already.
8
9struct IntLess
10{
11 bool operator()(const int & a, const int & b) const { return a < b; }
12};
13
15{
16 bool operator()(const int & a, const int & b) const { return a == b; }
17};
18
22
23// A comparator whose operator() is not const satisfies std::strict_weak_order
24// but is unusable by a const tree; StrictWeakOrder must reject it (see
25// aleph-concepts.md §2.2).
27{
28 bool operator()(const int & a, const int & b) { return a < b; }
29};
30
33
34// A functor with DIFFERENT const and non-const operator() overloads: the
35// const overload alone satisfies the old (const-only) StrictWeakOrder, but
36// mutating BST paths (Gen_Avl_Tree::insert -> search_and_stack_avl) invoke
37// cmp as a non-const lvalue and select the non-const overload instead,
38// which doesn't return bool. Caught during a codex review of this branch;
39// reproduced against Aleph::Avl_Tree<int, MixedConstCmp>::insert(), which
40// fails at tpl_avl.H:153 if this concept only checks the const shape.
42{
43 bool operator()(const int & a, const int & b) const { return a < b; }
44 void operator()(const int & a, const int & b) { (void) a; (void) b; }
45};
46
49
50TEST(AhConceptsHeaderTest, IsSelfContained)
51{
52 IntLess less;
53 EXPECT_TRUE(less(1, 2));
54 EXPECT_FALSE(less(2, 1));
55}
C++20 concepts hub: comparison, BST policy, and Aleph container concepts.
A callable that takes two const T& and returns bool.
Definition ah-concepts.H:98
Equivalence relation constraint for equality comparators.
Strict weak ordering constraint for BST comparators.
#define TEST(name)
bool operator()(const int &a, const int &b) const
bool operator()(const int &a, const int &b) const
void operator()(const int &a, const int &b)
bool operator()(const int &a, const int &b) const
bool operator()(const int &a, const int &b)