Live Cells C++
Reactive Programming for C++
Loading...
Searching...
No Matches
equality.hpp
1/*
2 * live_cells_cpp
3 * Copyright (C) 2024 Alexander Gutev <alex.gutev@gmail.com>
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you
6 * may not use this file except in compliance with the License. You
7 * may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 */
17
18#ifndef LIVE_CELLS_EQUALITY_HPP
19#define LIVE_CELLS_EQUALITY_HPP
20
21#include <typeinfo>
22
23#include "keys.hpp"
24#include "computed.hpp"
25#include "util.hpp"
26
27namespace live_cells {
28
29 namespace internal {
30
34 struct eq_cell_key : value_key<key_ref,key_ref> {
35 using value_key<key_ref,key_ref>::value_key;
36 };
37
41 struct neq_cell_key : value_key<key_ref,key_ref> {
42 using value_key<key_ref,key_ref>::value_key;
43 };
44
45 } // internal
46
56 template <typename T, typename U>
57 auto operator ==(const T &a, const U &b) requires (
60 ) {
61 typedef internal::eq_cell_key key;
62
63 auto cell_a = ensure_cell(a);
64 auto cell_b = ensure_cell(b);
65
66 return computed(key_ref::create<key>(cell_a.key(), cell_b.key()), cell_a, cell_b, [] (auto a, auto b) {
67 return a == b;
68 });
69 }
70
80 template <typename T, typename U>
81 auto operator !=(const T &a, const U &b) requires (
84 ) {
85 typedef internal::neq_cell_key key;
86
87 auto cell_a = ensure_cell(a);
88 auto cell_b = ensure_cell(b);
89
90 return computed(key_ref::create<key>(cell_a.key(), cell_b.key()), cell_a, cell_b, [] (auto a, auto b) {
91 return a != b;
92 });
93 }
94
95} // live_cells
96
97#endif /* LIVE_CELLS_EQUALITY_HPP */
A computed cell which determines its argument cells at runtime.
Definition dynamic_compute_cell.hpp:153
Defines the interface for a key which uniquely identifies a cell.
Definition keys.hpp:33
key_ref key() const
Get the key identifying the cell.
Definition stateful_cell.hpp:74
value_key(key_ref value, Ts... rest)
Create a key distinguished from other keys by one or more values.
Definition keys.hpp:167
Concept specifying that T is either a Cell or a value that can be converted to a constant_cell.
Definition constant_cell.hpp:141
Defines the cell protocol.
Definition types.hpp:128
Definition boolean.hpp:26
auto computed(F &&compute)
Create a cell with a value that is a function of one or more argument cells.
Definition computed.hpp:45
auto operator==(const T &a, const U &b)
Create a Cell that compares two cells for equality by ==.
Definition equality.hpp:57
auto ensure_cell(const Cell auto &thing)
Ensure that thing is a Cell.
Definition constant_cell.hpp:155
auto operator!=(const T &a, const U &b)
Create a Cell that compares two cells for inequality by !=.
Definition equality.hpp:81