Krita Source Code Documentation
Loading...
Searching...
No Matches
KisZug.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#ifndef KISZUG_H
7#define KISZUG_H
8
9#include <QtGlobal>
10#include <type_traits>
11#include "KisMpl.h"
12#include <zug/transducer/map.hpp>
13#include <zug/reducing/last.hpp>
14
27namespace kiszug {
28
29template <typename T>
30constexpr auto map_static_cast = zug::map([](auto&& x) { return static_cast<T>(x); });
31
32template <typename T>
33constexpr auto map_multiply = [] (T coeff) { return zug::map([coeff](auto&& x) { return x * coeff; }); };
34
35template <typename T>
36constexpr auto map_equal = [] (T value) { return zug::map([value](auto&& x) { return x == value; }); };
37
38template <typename T>
39constexpr auto map_not_equal = [] (T value) { return zug::map([value](auto&& x) { return x != value; }); };
40
41template <typename T>
42constexpr auto map_greater = [] (T value) { return zug::map([value](auto&& x) { return x > value; }); };
43template <typename T>
44constexpr auto map_greater_equal = [] (T value) { return zug::map([value](auto&& x) { return x >= value; }); };
45
46template <typename T>
47constexpr auto map_less = [] (T value) { return zug::map([value](auto&& x) { return x < value; }); };
48
49template <typename T>
50constexpr auto map_less_equal = [] (T value) { return zug::map([value](auto&& x) { return x <= value; }); };
51
52template <>
53inline constexpr auto map_equal<qreal> = [] (qreal value) { return zug::map([value](auto&& x) { return qFuzzyCompare(x, value); }); };
54
55template <>
56inline constexpr auto map_not_equal<qreal> = [] (qreal value) { return zug::map([value](auto&& x) { return !qFuzzyCompare(x, value); }); };
57
58template <>
59inline constexpr auto map_greater_equal<qreal> = [] (qreal value) { return zug::map([value](auto&& x) { return x >= value || qFuzzyCompare(x, value); }); };
60
61template <>
62inline constexpr auto map_less_equal<qreal> = [] (qreal value) { return zug::map([value](auto&& x) { return x <= value || qFuzzyCompare(x, value); }); };
63
64constexpr auto map_round = zug::map([](qreal x) -> int { return qRound(x); });
65
66// a state getter for an std::optional
67constexpr auto has_value = zug::map([](auto&& x) -> bool { return x.has_value(); });
68
69struct empty_t
70{
71};
72
73constexpr auto to_functor = [] (auto f) {
74 return
75 [=] (auto &&x) {
76 return f(zug::last)(empty_t{}, ZUG_FWD(x));
77 };
78};
79
80constexpr auto foreach_tuple =
81 [] (auto mapping) {
82 return zug::map([=] (auto &&t) {
83 return kismpl::apply_to_tuple(to_functor(mapping), ZUG_FWD(t));
84 });
85 };
86
87constexpr auto foreach_arg =
88 [] (auto mapping) {
89 return zug::map([=] (auto&&... t) {
90 return std::make_tuple(zug::compat::invoke(to_functor(mapping), ZUG_FWD(t))...);
91 });
92 };
93
94} // namespace kiszug
95
96#endif // KISZUG_H
float value(const T *src, size_t ch)
static bool qFuzzyCompare(half p1, half p2)
auto apply_to_tuple(F f, Tuple &&t)
Definition KisMpl.h:60
constexpr auto map_not_equal
Definition KisZug.h:39
constexpr auto map_greater_equal< qreal >
Definition KisZug.h:59
constexpr auto foreach_arg
Definition KisZug.h:87
constexpr auto map_less_equal< qreal >
Definition KisZug.h:62
constexpr auto foreach_tuple
Definition KisZug.h:80
constexpr auto map_multiply
Definition KisZug.h:33
constexpr auto map_static_cast
Definition KisZug.h:30
constexpr auto has_value
Definition KisZug.h:67
constexpr auto map_not_equal< qreal >
Definition KisZug.h:56
constexpr auto map_equal
Definition KisZug.h:36
constexpr auto map_less
Definition KisZug.h:47
constexpr auto map_less_equal
Definition KisZug.h:50
constexpr auto to_functor
Definition KisZug.h:73
constexpr auto map_equal< qreal >
Definition KisZug.h:53
constexpr auto map_greater
Definition KisZug.h:42
constexpr auto map_greater_equal
Definition KisZug.h:44
constexpr auto map_round
Definition KisZug.h:64