Simple-Utility v2.3.1
Loading...
Searching...
No Matches
Arithmetic.hpp
Go to the documentation of this file.
1// Copyright Dominic Koepke 2019 - 2023.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// https://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef SL_UTILITY_FUNCTIONAL_ARITHMETIC_HPP
7#define SL_UTILITY_FUNCTIONAL_ARITHMETIC_HPP
8
11
13{
25 inline constexpr auto plus = envelop<Transform>(
26 []<class TLhs, class TRhs>(TLhs&& lhs, TRhs&& rhs) -> decltype(std::forward<TLhs>(lhs) + std::forward<TRhs>(rhs))
27 {
28 static_assert(concepts::plus_with<TLhs, TRhs>, "Arguments are not usable as operands of binary operator +.");
29
30 return std::forward<TLhs>(lhs) + std::forward<TRhs>(rhs);
31 });
32
36 inline constexpr auto minus = envelop<Transform>(
37 []<class TLhs, class TRhs>(TLhs&& lhs, TRhs&& rhs) -> decltype(std::forward<TLhs>(lhs) - std::forward<TRhs>(rhs))
38 {
39 static_assert(concepts::minus_with<TLhs, TRhs>, "Arguments are not usable as operands of binary operator -.");
40
41 return std::forward<TLhs>(lhs) - std::forward<TRhs>(rhs);
42 });
43
47 inline constexpr auto multiplies = envelop<Transform>(
48 []<class TLhs, class TRhs>(TLhs&& lhs, TRhs&& rhs) -> decltype(std::forward<TLhs>(lhs) * std::forward<TRhs>(rhs))
49 {
50 static_assert(concepts::multiplies_with<TLhs, TRhs>, "Arguments are not usable as operands of binary operator *.");
51
52 return std::forward<TLhs>(lhs) * std::forward<TRhs>(rhs);
53 });
54
58 inline constexpr auto divides = envelop<Transform>(
59 []<class TLhs, class TRhs>(TLhs&& lhs, TRhs&& rhs) -> decltype(std::forward<TLhs>(lhs) / std::forward<TRhs>(rhs))
60 {
61 static_assert(concepts::divides_with<TLhs, TRhs>, "Arguments are not usable as operands of binary operator /.");
62
63 return std::forward<TLhs>(lhs) / std::forward<TRhs>(rhs);
64 });
65
69 inline constexpr auto modulus = envelop<Transform>(
70 []<class TLhs, class TRhs>(TLhs&& lhs, TRhs&& rhs) -> decltype(std::forward<TLhs>(lhs) % std::forward<TRhs>(rhs))
71 {
72 static_assert(concepts::modulus_with<TLhs, TRhs>, "Arguments are not usable as operands of binary operator %.");
73
74 return std::forward<TLhs>(lhs) % std::forward<TRhs>(rhs);
75 });
76
80 inline constexpr auto negate = envelop<Transform>(
81 []<class T>(T&& value) -> decltype(-std::forward<T>(value))
82 {
83 static_assert(concepts::negate<T>, "Argument is not usable as operand of unary operator -.");
84
85 return -std::forward<T>(value);
86 });;
87
91}
92
93#endif
Determines whether two types can be used in operator / expressions.
Definition: operators.hpp:1067
Determines whether two types can be used in operator - expressions.
Definition: operators.hpp:907
Determines whether two types can be used in operator % expressions.
Definition: operators.hpp:1147
Determines whether two types can be used in operator * expressions.
Definition: operators.hpp:987
Determines whether a type can be used in operator - expression.
Definition: operators.hpp:804
Determines whether two types can be used in operator + expressions.
Definition: operators.hpp:827
Checks whether the given template type is usable as value type for unique_handle types.
Definition: unique_handle.hpp:161
constexpr auto modulus
Functional object which forwards the params to binary operator % and returns the result.
Definition: Arithmetic.hpp:69
constexpr auto plus
Functional object which forwards the params to binary operator + and returns the result.
Definition: Arithmetic.hpp:25
constexpr auto divides
Functional object which forwards the params to binary operator / and returns the result.
Definition: Arithmetic.hpp:58
constexpr auto negate
Functional object which forwards the param to unary operator - and returns the result.
Definition: Arithmetic.hpp:80
constexpr auto multiplies
Functional object which forwards the params to binary operator * and returns the result.
Definition: Arithmetic.hpp:47
constexpr auto minus
Functional object which forwards the params to binary operator - and returns the result.
Definition: Arithmetic.hpp:36
Definition: Arithmetic.hpp:13