Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_ca_concepts.H
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
56#ifndef TPL_CA_CONCEPTS_H
57#define TPL_CA_CONCEPTS_H
58
59#include <concepts>
60#include <cstddef>
61#include <tuple>
62#include <type_traits>
63#include <utility>
64
65#include <ca-traits.H>
66
67namespace Aleph {
68namespace CA {
69
78template <typename T>
79concept CellState = std::regular<T>;
80
90template <typename C, std::size_t N>
91concept Coord = std::regular<C> and requires(C c, std::size_t i) {
92 { c[i] } -> std::convertible_to<ca_index_t>;
93 { C{}.size() } -> std::convertible_to<std::size_t>;
94} and (std::tuple_size<C>::value == N);
95
112template <typename L>
113concept LatticeLike = requires {
114 typename L::state_type;
115 typename L::coord_type;
116} and CellState<typename L::state_type> and requires(L &lat, const L &clat, const typename L::coord_type &c, const typename L::state_type &v, std::size_t d) {
117 { clat.dimension() } -> std::convertible_to<std::size_t>;
118 { clat.size(d) } -> std::convertible_to<std::size_t>;
119 { clat.at(c) } -> std::convertible_to<typename L::state_type>;
120 { lat.set(c, v) };
121};
122
143template <typename H>
145 requires {
146 typename H::coord_type;
147 { H::rank_v } -> std::convertible_to<std::size_t>;
148 { H::size_v } -> std::convertible_to<std::size_t>;
149 }
150 and requires(const H &h, const typename H::coord_type &center) {
151 { h.radius() } -> std::convertible_to<std::size_t>;
152 { h.size() } -> std::convertible_to<std::size_t>;
153 h.for_each_offset(center, [](const auto &) {});
154 };
155
165template <typename R, typename L>
168and requires(const R &r, const typename L::state_type &s, Neighbor_View<typename L::state_type> v) {
169 { r(s, v) } -> std::convertible_to<typename L::state_type>;
170 };
171
184template <typename R, typename L>
187and requires(const R &r, const typename L::state_type &s,
189 const Cell_Context<L::rank> &ctx) {
190 { r(s, v, ctx) } -> std::convertible_to<typename L::state_type>;
191 };
192
202template <typename R, typename L>
204
224template <typename Rule, typename State, std::size_t Rank>
225[[nodiscard]] inline State apply_rule(const Rule &r,
226 const State &s,
228 const Cell_Context<Rank> &ctx)
229{
230 if constexpr (requires { r(s, v, ctx); })
231 return r(s, v, ctx);
232 else
233 return r(s, v);
234}
235
240template <typename L>
241concept HasRefreshHalo = requires(L &l) { l.refresh_halo(); };
242
243// Forward declarations only: HexRenderable/TriRenderable below name these
244// types in non-dependent expressions. std::declval<T>() (unlike `T{}`)
245// never constructs a T, so it only needs T declared here, not complete;
246// both are complete by the time the concepts are actually evaluated, at
247// their use sites in ca-svg.H/ca-tikz.H, which include the full
248// tpl_ca_hex_lattice.H/tpl_ca_triangular_lattice.H definitions. Including
249// those headers here instead would be circular (they include this one).
250struct Hex_Axial;
251struct Tri_Coord;
252
256template <typename Lattice>
257concept HexRenderable = requires(const Lattice &lat) {
258 lat.rows();
259 lat.cols();
260 lat.at_axial(std::declval<Hex_Axial>());
261};
262
266template <typename Lattice>
267concept TriRenderable = requires(const Lattice &lat) {
268 lat.rows();
269 lat.cols();
270 lat.at_tri(std::declval<Tri_Coord>());
271};
272
273} // namespace CA
274} // namespace Aleph
275
276#endif // TPL_CA_CONCEPTS_H
long double h
Definition btreepic.C:154
Common typedefs and tag types for the Cellular Automata module.
Pure local transition function (Phase 0–7 signature).
A type usable as the value stored inside a cell.
Context-aware local transition function (Phase 8).
A coordinate type with N integral components.
Detect whether a lattice exposes a refresh_halo() method (the hallmark of a Ghost_Lattice or any othe...
Detect whether a lattice exposes the hexagonal-grid query interface (rows(), cols(),...
Storage + topology that carries the cell values.
Connectivity pattern around a coordinate.
Local transition function (any supported signature).
Detect whether a lattice exposes the triangular-grid query interface (rows(), cols(),...
#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
@ R
Recovered (and immune).
std::span< const T > Neighbor_View
Read-only view over a contiguous range of neighbour values.
Definition ca-traits.H:90
State apply_rule(const Rule &r, const State &s, Neighbor_View< State > v, const Cell_Context< Rank > &ctx)
Invoke a rule, optionally forwarding the per-cell context.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
and
Check uniqueness with explicit hash + equality functors.
Per-cell context handed to rules that need to know "where" and "when" they are firing.
Definition ca-traits.H:106
Axial integer coordinates (q, r) of a hex cell.
Coordinates of a triangular cell as (i, j) integers.
gsl_rng * r
DynList< int > l