Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ah-concepts.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
82# ifndef AH_CONCEPTS_H
83# define AH_CONCEPTS_H
84
85# include <concepts>
86# include <type_traits>
87# include <cstddef>
88# include <functional>
89# include <utility>
90
91namespace Aleph
92{
97 template <typename F, typename T>
99 requires(const F & f, const T & a, const T & b)
100 {
101 { f(a, b) } -> std::convertible_to<bool>;
102 };
103
124 template <typename F, typename T>
126 std::strict_weak_order<F, T, T> and
127 std::strict_weak_order<const F &, const T &, const T &>;
128
141 template <typename F, typename T>
143 std::equivalence_relation<F, T, T> and
144 std::equivalence_relation<const F &, const T &, const T &>;
145
162 template <typename T, typename Key>
163 concept BSTPolicy =
164 requires { typename T::Node; } and
165 requires(T & t, T & t2, const T & ct,
166 typename T::Node * p, const Key & key)
167 {
168 { t.getRoot() } -> std::convertible_to<typename T::Node *>;
169 { t.search(key) } -> std::convertible_to<typename T::Node *>;
170 { t.search_or_insert(p) } -> std::convertible_to<typename T::Node *>;
171 { t.insert_dup(p) } -> std::convertible_to<typename T::Node *>;
172 { t.remove(key) } -> std::convertible_to<typename T::Node *>;
173 { ct.verify() } -> std::convertible_to<bool>;
174 { t.swap(t2) };
175 { t.get_compare() };
176 requires not requires { ct.getRoot(); } or requires {
177 { ct.getRoot() } -> std::convertible_to<const typename T::Node *>;
178 };
179 requires (not requires { ct.search(key); } or
180 requires
181 {
182 { ct.search(key) } -> std::convertible_to<const typename T::Node *>;
183 });
184 };
185
195 template <typename T>
196 concept AlephArrayConvertible = requires(T c)
197 {
198 typename T::Item_Type;
199 { c.get_it() };
200 };
201
230 template <typename C>
232 requires { typename C::Item_Type; } and
233 requires(C & c, const C & cc, const typename C::Item_Type & val)
234 {
235 { cc.size() } -> std::convertible_to<std::size_t>;
236 { cc.is_empty() } -> std::convertible_to<bool>;
237 c.append(val);
238 } and
239 // mutable_for_each must accept a void(Item_Type&) callable
240 requires(C & c)
241 {
242 c.mutable_for_each([](typename C::Item_Type &) {});
243 };
244
266 template <typename C>
269 requires(const C & cc)
270 {
271 cc.get_it();
272 };
273
289 template <typename It>
291 requires(It & it)
292 {
293 static_cast<bool>(it.has_curr());
294 it.get_curr();
295 it.next_ne();
296 };
297
310 template <typename C>
312 requires
313 {
314 typename C::Item_Type;
315 typename C::Iterator;
316 } and
318 std::constructible_from<typename C::Iterator, const C &>;
319
328 template <typename C>
330 requires { typename C::Item_Type; } and
331 requires(C & c, bool (&op)(const typename C::Item_Type &))
332 {
333 { c.traverse(op) } -> std::convertible_to<bool>;
334 };
335
343 template <typename C>
347 requires(const C & cc)
348 {
349 { cc.size() } -> std::convertible_to<std::size_t>;
350 { cc.is_empty() } -> std::convertible_to<bool>;
351 };
352
357 template <typename C>
360 requires(C & c, const typename C::Item_Type & v)
361 {
362 c.append(v);
363 };
364
372 template <typename C>
374 requires(const C & c)
375 {
376 c.begin();
377 c.end();
378 typename C::value_type;
379 };
380
386 template <typename T>
388 std::is_integral_v<std::remove_cv_t<T>> and
389 not std::is_same_v<std::remove_cv_t<T>, bool>;
390
406 template <typename T>
407 concept ArrayStorable = std::default_initializable<T> and std::movable<T>;
408
423 template <typename F, typename T>
425 requires(const F & f, const T & a, const T & b)
426 {
427 { f(a, b) } -> std::convertible_to<T>;
428 };
429
440 template <typename M, typename T>
441 concept StaticMonoid =
442 requires(const T & a, const T & b)
443 {
444 { M::identity() } -> std::convertible_to<T>;
445 { M::combine(a, b) } -> std::convertible_to<T>;
446 };
447
460 template <typename F, typename... Args>
461 concept CallableWith =
462 requires(F && f, Args &&... args)
463 {
464 std::forward<F>(f)(std::forward<Args>(args)...);
465 };
466
479 template <typename F, typename... Args>
482 requires(F && f, Args &&... args)
483 {
484 static_cast<bool>(std::forward<F>(f)(std::forward<Args>(args)...));
485 };
486
487 namespace concepts_detail
488 {
490 template <class N>
492 requires
493 {
494 typename N::key_type;
495 { N::NullPtr } -> std::convertible_to<N *>;
496 } and
497 requires(N * p)
498 {
499 { p->getL() } -> std::same_as<N *&>;
500 { p->getR() } -> std::same_as<N *&>;
501 { p->get_key() } -> std::convertible_to<typename N::key_type &>;
502 };
503 } // namespace concepts_detail
504
516 template <class Node>
518
528 template <class Node>
531 requires(std::remove_cv_t<Node> * p)
532 {
533 { p->getCount() } -> std::convertible_to<std::size_t>;
534 };
535
536 namespace concepts_detail
537 {
550 template <class T, class Deferred>
551 struct defer
552 {
553 using type = T;
554 };
555
565 template <class Container, class Deferred>
567 {
568 using type = decltype(std::declval<typename defer<Container, Deferred>::type::Iterator &>().get_curr());
569 };
570
571 template <class Sig>
572 struct invoke_as;
573
586 template <class R, class... A>
587 struct invoke_as<R(A...)>
588 {
603 template <class F>
604 static R call(F & f, A... a)
605 {
606 if constexpr (std::is_void_v<R>)
607 std::invoke(f, std::forward<A>(a)...);
608 else
609 return std::invoke(f, std::forward<A>(a)...);
610 }
611 };
612 } // namespace concepts_detail
613
614} // namespace Aleph
615
616# endif // AH_CONCEPTS_H
Concept that identifies types that can be converted or used as an Aleph Array.
A traversable, AlephIterable container with a size.
A type that yields an AlephIterator over its Item_Types.
An Aleph cursor-style iterator, as generic library code uses it.
An iterable container that grows at its back with append().
Concept for Aleph-w mutable sequential containers.
Concept for Aleph-w sequential containers that can be iterated.
A container whose items can be visited with traverse().
An element type the Aleph arrays can store.
Concept for BST tree policies used by DynSetTree.
A binary tree node usable by tpl_binNodeUtils.H.
A callable that takes two const T& and returns bool.
Definition ah-concepts.H:98
f(args...) is a valid call expression, exactly as written.
A binary functor closed over T.
Equivalence relation constraint for equality comparators.
Integral value accepted by linear-time integer sorting algorithms.
f(args...) is a valid call whose result is usable as a condition.
A binary tree node that also keeps subtree sizes (rank).
A static monoid: M::identity() and M::combine(a, b).
A container with STL-style begin()/end() and value_type.
Strict weak ordering constraint for BST comparators.
Unqualified form of BinNodeLike, applied to a cv-free node type.
#define N
Definition fib.C:294
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
and
Check uniqueness with explicit hash + equality functors.
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:105
auto get_curr() const
Return the current tuple (bounds-checked).
Definition ah-zip.H:145
T itself, made dependent on Deferred.
static R call(F &f, A... a)
Invoke f(a...) converting the result to R.
What Container::Iterator::get_curr() yields, deferred.
decltype(std::declval< typename defer< Container, Deferred >::type::Iterator & >().get_curr()) type
Filter_Iterator< DynList< int >, DynList< int >::Iterator, Par > It
Definition test_htlist.C:61