Aleph-w 7.10.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
84# ifndef AH_CONCEPTS_H
85# define AH_CONCEPTS_H
86
87# include <concepts>
88# include <type_traits>
89# include <cstddef>
90# include <functional>
91# include <utility>
92
93namespace Aleph
94{
99 template <typename F, typename T>
101 requires(const F & f, const T & a, const T & b)
102 {
103 { f(a, b) } -> std::convertible_to<bool>;
104 };
105
126 template <typename F, typename T>
128 std::strict_weak_order<F, T, T> and
129 std::strict_weak_order<const F &, const T &, const T &>;
130
143 template <typename F, typename T>
145 std::equivalence_relation<F, T, T> and
146 std::equivalence_relation<const F &, const T &, const T &>;
147
164 template <typename T, typename Key>
165 concept BSTPolicy =
166 requires { typename T::Node; } and
167 requires(T & t, T & t2, const T & ct,
168 typename T::Node * p, const Key & key)
169 {
170 { t.getRoot() } -> std::convertible_to<typename T::Node *>;
171 { t.search(key) } -> std::convertible_to<typename T::Node *>;
172 { t.search_or_insert(p) } -> std::convertible_to<typename T::Node *>;
173 { t.insert_dup(p) } -> std::convertible_to<typename T::Node *>;
174 { t.remove(key) } -> std::convertible_to<typename T::Node *>;
175 { ct.verify() } -> std::convertible_to<bool>;
176 { t.swap(t2) };
177 { t.get_compare() };
178 requires not requires { ct.getRoot(); } or requires {
179 { ct.getRoot() } -> std::convertible_to<const typename T::Node *>;
180 };
181 requires (not requires { ct.search(key); } or
182 requires
183 {
184 { ct.search(key) } -> std::convertible_to<const typename T::Node *>;
185 });
186 };
187
197 template <typename T>
198 concept AlephArrayConvertible = requires(T c)
199 {
200 typename T::Item_Type;
201 { c.get_it() };
202 };
203
232 template <typename C>
234 requires { typename C::Item_Type; } and
235 requires(C & c, const C & cc, const typename C::Item_Type & val)
236 {
237 { cc.size() } -> std::convertible_to<std::size_t>;
238 { cc.is_empty() } -> std::convertible_to<bool>;
239 c.append(val);
240 } and
241 // mutable_for_each must accept a void(Item_Type&) callable
242 requires(C & c)
243 {
244 c.mutable_for_each([](typename C::Item_Type &) {});
245 };
246
268 template <typename C>
271 requires(const C & cc)
272 {
273 cc.get_it();
274 };
275
291 template <typename It>
293 requires(It & it)
294 {
295 static_cast<bool>(it.has_curr());
296 it.get_curr();
297 it.next_ne();
298 };
299
312 template <typename It>
315 requires(It & it) { it.get_curr_ne(); } and
316 std::same_as<decltype(std::declval<It &>().get_curr_ne()),
317 decltype(std::declval<It &>().get_curr())>;
318
333 template <typename C>
335 requires
336 {
337 typename C::Item_Type;
338 typename C::Iterator;
339 } and
341 std::constructible_from<typename C::Iterator, C &>;
342
351 template <typename C>
353 requires { typename C::Item_Type; } and
354 requires(C & c, bool (&op)(const typename C::Item_Type &))
355 {
356 { c.traverse(op) } -> std::convertible_to<bool>;
357 };
358
366 template <typename C>
370 requires(const C & cc)
371 {
372 { cc.size() } -> std::convertible_to<std::size_t>;
373 { cc.is_empty() } -> std::convertible_to<bool>;
374 };
375
380 template <typename C>
383 requires(C & c, const typename C::Item_Type & v)
384 {
385 c.append(v);
386 };
387
397 template <typename C, typename Item>
398 concept AppendableWith = requires(C & c, Item && item)
399 {
400 c.append(std::forward<Item>(item));
401 };
402
410 template <typename C, typename Item>
411 concept InsertableWith = requires(C & c, Item && item)
412 {
413 c.insert(std::forward<Item>(item));
414 };
415
423 template <typename C>
425 requires(const C & c)
426 {
427 c.begin();
428 c.end();
429 typename C::value_type;
430 };
431
437 template <typename T>
439 std::is_integral_v<std::remove_cv_t<T>> and
440 not std::is_same_v<std::remove_cv_t<T>, bool>;
441
457 template <typename T>
458 concept ArrayStorable = std::default_initializable<T> and std::movable<T>;
459
474 template <typename F, typename T>
476 requires(const F & f, const T & a, const T & b)
477 {
478 { f(a, b) } -> std::convertible_to<T>;
479 };
480
491 template <typename M, typename T>
492 concept StaticMonoid =
493 requires(const T & a, const T & b)
494 {
495 { M::identity() } -> std::convertible_to<T>;
496 { M::combine(a, b) } -> std::convertible_to<T>;
497 };
498
511 template <typename F, typename... Args>
512 concept CallableWith =
513 requires(F && f, Args &&... args)
514 {
515 std::forward<F>(f)(std::forward<Args>(args)...);
516 };
517
530 template <typename F, typename... Args>
532 CallableWith<F, Args...> and
533 requires(F && f, Args &&... args)
534 {
535 static_cast<bool>(std::forward<F>(f)(std::forward<Args>(args)...));
536 };
537
549 template <typename F, typename... Args>
550 concept InvocableWith = std::invocable<F, Args...>;
551
561 template <typename F, typename... Args>
563 InvocableWith<F, Args...> and
564 requires(F && f, Args &&... args)
565 {
566 static_cast<bool>(std::invoke(std::forward<F>(f), std::forward<Args>(args)...));
567 };
568
578 template <typename F, typename... Args>
580 PredicateWith<F, Args...> and
581 requires(F && f, Args &&... args)
582 {
583 { static_cast<bool>(std::forward<F>(f)(std::forward<Args>(args)...)) } noexcept;
584 };
585
586 namespace concepts_detail
587 {
589 template <class N>
591 requires
592 {
593 typename N::key_type;
594 { N::NullPtr } -> std::convertible_to<N *>;
595 } and
596 requires(N * p)
597 {
598 { p->getL() } -> std::same_as<N *&>;
599 { p->getR() } -> std::same_as<N *&>;
600 { p->get_key() } -> std::convertible_to<typename N::key_type &>;
601 };
602 } // namespace concepts_detail
603
615 template <class Node>
617
627 template <class Node>
630 requires(std::remove_cv_t<Node> * p)
631 {
632 { p->getCount() } -> std::convertible_to<std::size_t>;
633 };
634
635 namespace concepts_detail
636 {
649 template <class T, class Deferred>
650 struct defer
651 {
652 using type = T;
653 };
654
664 template <class Container, class Deferred>
666 {
667 using type = decltype(std::declval<typename defer<Container, Deferred>::type::Iterator &>().get_curr());
668 };
669
676 template <class Container, class Deferred>
678 {
679 using type = const std::remove_reference_t<typename traverse_arg<Container, Deferred>::type> &;
680 };
681
688 template <class Op, class T>
690 {
691 using type = std::decay_t<std::invoke_result_t<Op, const T &>>;
692 };
693
705 template <class R, class Op, class T>
707 typename std::conditional_t<std::is_void_v<R>, decayed_invoke_result<Op, T>,
708 std::type_identity<R>>::type;
709
710 template <class Sig>
711 struct invoke_as;
712
725 template <class R, class... A>
726 struct invoke_as<R(A...)>
727 {
742 template <class F>
743 static R call(F & f, A... a)
744 {
745 if constexpr (std::is_void_v<R>)
746 std::invoke(f, std::forward<A>(a)...);
747 else
748 return std::invoke(f, std::forward<A>(a)...);
749 }
750 };
751 } // namespace concepts_detail
752
753} // namespace Aleph
754
755# endif // AH_CONCEPTS_H
Number Theoretic Transform over Z / MOD Z.
Definition ntt.H:115
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 AlephIterator whose get_curr_ne() gives what get_curr() gives, without its check.
A container whose append() accepts an argument of type Item.
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.
f(args...) is a valid call expression, exactly as written.
A binary functor closed over T.
Equivalence relation constraint for equality comparators.
A container whose insert() accepts an argument of type Item.
Integral value accepted by linear-time integer sorting algorithms.
std::invoke(f, args...) is valid and usable as a condition.
std::invoke(f, args...) is valid.
PredicateWith<F, Args...>, and neither the call nor the conversion of its result to bool can throw.
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.
FFT< double > F
typename std::conditional_t< std::is_void_v< R >, decayed_invoke_result< Op, T >, std::type_identity< R > >::type map_result_t
Item type of a mapping: R, or the decayed type that Op returns when R is void.
Main namespace for Aleph-w library functions.
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:152
auto get_curr() const
Return the current tuple (bounds-checked).
Definition ah-zip.H:192
and
Check uniqueness with explicit hash + equality functors.
The result of std::invoke(op, item) with item a const T &, without references and const.
std::decay_t< std::invoke_result_t< Op, const T & > > type
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
What a constant iterator-driven traverse() passes to its operation: the item as a constant lvalue ref...
const std::remove_reference_t< typename traverse_arg< Container, Deferred >::type > & type
Filter_Iterator< DynList< int >, DynList< int >::Iterator, Par > It
Definition test_htlist.C:61