ProjGeom 1.0.11
Loading...
Searching...
No Matches
common_concepts.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <cmath>
8#include <concepts>
9#include <numeric>
10#include <type_traits>
11#include <utility>
12// #include <ranges>
13namespace STD_ALT = std;
14
15namespace fun {
16
23 template <typename T> using Value_type = typename T::value_type;
24
32 template <typename T> using Element_type =
33 typename std::decay<decltype(back(std::declval<T>()))>::type;
34
40 template <typename T>
41 concept Sequence = requires(T t, Element_type<T> x) {
42 { t.size() } -> STD_ALT::convertible_to<std::size_t>;
43 { t.empty() } -> STD_ALT::convertible_to<bool>;
44 { t.back() } -> STD_ALT::same_as<Element_type<T>>;
45 { t.emplace_back(x) };
46 };
47
55 template <typename K>
56 concept Ring = STD_ALT::equality_comparable<K> && requires(K a, K pt_b) {
57 { a + pt_b } -> STD_ALT::convertible_to<K>;
58 { a - pt_b } -> STD_ALT::convertible_to<K>;
59 { a * pt_b } -> STD_ALT::convertible_to<K>;
60 { a += pt_b } -> STD_ALT::same_as<K&>;
61 { a -= pt_b } -> STD_ALT::same_as<K&>;
62 { a *= pt_b } -> STD_ALT::same_as<K&>;
63 { -a } -> STD_ALT::convertible_to<K>;
64 { K(a) } -> STD_ALT::convertible_to<K>;
65 { K(0) } -> STD_ALT::convertible_to<K>;
66 };
67
74 template <typename K>
75 concept OrderedRing = Ring<K> && STD_ALT::totally_ordered<K>;
76
83 template <typename Z>
84 concept Integral = OrderedRing<Z> && requires(Z a, Z pt_b) {
85 { a % pt_b } -> STD_ALT::convertible_to<Z>;
86 { a / pt_b } -> STD_ALT::convertible_to<Z>;
87 { a %= pt_b } -> STD_ALT::same_as<Z&>;
88 { a /= pt_b } -> STD_ALT::same_as<Z&>;
89 };
90
91} // namespace fun
Integral concept.
Definition common_concepts.h:84
Ordered ring concept.
Definition common_concepts.h:75
Ring concept.
Definition common_concepts.h:56
Sequence.
Definition common_concepts.h:41
Definition ck_concepts.hpp:11
typename T::value_type Value_type
Value type of a type.
Definition common_concepts.h:23
typename std::decay< decltype(back(std::declval< T >()))>::type Element_type
Element type of a sequence.
Definition common_concepts.h:33