Live Cells C++
Reactive Programming for C++
Loading...
Searching...
No Matches
mutable_computed.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_MUTABLE_COMPUTED_HPP
19#define LIVE_CELLS_MUTABLE_COMPUTED_HPP
20
21#include <tuple>
22#include <utility>
23#include <concepts>
24
25#include "static_mutable_compute_cell.hpp"
26#include "dynamic_mutable_compute_cell.hpp"
27#include "util.hpp"
28
29namespace live_cells {
62 template <std::invocable F, typename R>
63 auto mutable_computed(F&& fn, R&& reverse) {
65 std::forward<F>(fn),
66 std::forward<R>(reverse)
67 );
68 }
69
108 template <std::invocable F, typename R>
111 std::forward<F>(fn),
112 std::forward<R>(reverse)
113 );
114 }
115
150 template <std::invocable F, typename R>
151 auto mutable_computed(key_ref key, F&& fn, R&& reverse) {
153 key,
154 std::forward<F>(fn),
155 std::forward<R>(reverse)
156 );
157 }
158
199 template <std::invocable F, typename R>
202 key,
203 std::forward<F>(fn),
204 std::forward<R>(reverse)
205 );
206 }
207
233 template <typename A1, typename A2, typename... As>
235 auto packed = internal::pack<2>(arg1, arg2, args...);
236
237 auto fn_args = std::get<0>(packed);
238 auto compute = std::get<1>(packed);
239 auto reverse = std::get<2>(packed);
240
241 return std::apply([&] (auto... args) {
242 auto fn = [=] {
243 return compute(args.value()...);
244 };
245
246 return make_mutable_compute_cell(fn, reverse, args...);
247 }, fn_args);
248 }
249
282 template <typename A1, typename A2, typename... As>
284 auto packed = internal::pack<2>(arg1, arg2, args...);
285
286 auto fn_args = std::get<0>(packed);
287 auto compute = std::get<1>(packed);
288 auto reverse = std::get<2>(packed);
289
290 return std::apply([&] (auto... args) {
291 auto fn = [=] {
292 return compute(args.value()...);
293 };
294
295 return make_mutable_compute_cell(changes_only, fn, reverse, args...);
296 }, fn_args);
297 }
298
299
327 template <typename A1, typename A2, typename... As>
329 auto packed = internal::pack<2>(arg1, arg2, args...);
330
331 auto fn_args = std::get<0>(packed);
332 auto compute = std::get<1>(packed);
333 auto reverse = std::get<2>(packed);
334
335 return std::apply([&] (auto... args) {
336 auto fn = [=] {
337 return compute(args.value()...);
338 };
339
340 return make_mutable_compute_cell(key, fn, reverse, args...);
341 }, fn_args);
342 }
343
378 template <typename A1, typename A2, typename... As>
380 auto packed = internal::pack<2>(arg1, arg2, args...);
381
382 auto fn_args = std::get<0>(packed);
383 auto compute = std::get<1>(packed);
384 auto reverse = std::get<2>(packed);
385
386 return std::apply([&] (auto... args) {
387 auto fn = [=] {
388 return compute(args.value()...);
389 };
390
391 return make_mutable_compute_cell(changes_only, key, fn, reverse, args...);
392 }, fn_args);
393 }
394
395} // live_cells
396
397#endif /* LIVE_CELLS_MUTABLE_COMPUTED_HPP */
A computed cell which determines its argument cells at runtime.
Definition dynamic_compute_cell.hpp:153
Dynamically type key container.
Definition keys.hpp:76
Defines the interface for a key which uniquely identifies a cell.
Definition keys.hpp:33
Definition boolean.hpp:26
auto make_mutable_compute_cell(C compute, R reverse, As... args)
Create a static_mutable_compute_cell with compute function compute, reverse compute function reverse ...
Definition static_mutable_compute_cell.hpp:259
auto mutable_computed(F &&fn, R &&reverse)
Create a mutable computed cell with dynamically determined argument cells.
Definition mutable_computed.hpp:63
constexpr changes_only_option changes_only
Cell option specifying that the cell, to which it is applied, should only notify its observers when i...
Definition changes_only_state.hpp:101
Cell option specifying that the cell, to which it is applied, should only notify its observers when i...
Definition changes_only_state.hpp:94