Horizon
Loading...
Searching...
No Matches
arithmetic.hpp
Go to the documentation of this file.
1
2// Range v3 library
3//
4// Copyright Eric Niebler 2013-present
5//
6// Use, modification and distribution is subject to the
7// Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at
9// http://www.boost.org/LICENSE_1_0.txt)
10//
11// Project home: https://github.com/ericniebler/range-v3
12//
13#ifndef RANGES_V3_FUNCTIONAL_ARITHMETIC_HPP
14#define RANGES_V3_FUNCTIONAL_ARITHMETIC_HPP
15
16#include <concepts/concepts.hpp>
17
18#include <range/v3/detail/prologue.hpp>
19
20namespace ranges
21{
24 struct plus
25 {
26 template<typename T, typename U>
27 constexpr auto operator()(T && t, U && u) const -> decltype((T &&) t + (U &&) u)
28 {
29 return (T &&) t + (U &&) u;
30 }
31 using is_transparent = void;
32 };
33
34 struct minus
35 {
36 template<typename T, typename U>
37 constexpr auto operator()(T && t, U && u) const -> decltype((T &&) t - (U &&) u)
38 {
39 return (T &&) t - (U &&) u;
40 }
41 using is_transparent = void;
42 };
43
45 {
46 template<typename T, typename U>
47 constexpr auto operator()(T && t, U && u) const -> decltype((T &&) t * (U &&) u)
48 {
49 return (T &&) t * (U &&) u;
50 }
51 using is_transparent = void;
52 };
53
55 {
56 template<typename T, typename U>
57 constexpr auto operator()(T && t, U && u) const -> decltype((T &&) t | (U &&) u)
58 {
59 return (T &&) t | (U &&) u;
60 }
61 using is_transparent = void;
62 };
63
64 template<typename T>
66 {
67 // clang-format off
68 template<typename U>
69 constexpr auto CPP_auto_fun(operator())(U &&u)(const)
70 (
71 return static_cast<T>((U &&) u)
72 )
73 // clang-format on
74 };
75
76 template<typename T>
77 struct coerce
78 {
79 constexpr T & operator()(T & t) const
80 {
81 return t;
82 }
84 constexpr T const & operator()(T const & t) const
85 {
86 return t;
87 }
89 constexpr T operator()(T && t) const
90 {
91 return (T &&) t;
92 }
93 T operator()(T const &&) const = delete;
94 };
95
96 template<typename T>
97 struct coerce<T const> : coerce<T>
98 {};
99
100 template<typename T>
101 struct coerce<T &> : coerce<T>
102 {};
103
104 template<typename T>
105 struct coerce<T &&> : coerce<T>
106 {};
108} // namespace ranges
109
110#include <range/v3/detail/epilogue.hpp>
111
112#endif
Definition arithmetic.hpp:55
Definition arithmetic.hpp:78
constexpr T operator()(T &&t) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition arithmetic.hpp:89
constexpr T const & operator()(T const &t) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition arithmetic.hpp:84
Definition arithmetic.hpp:66
Definition arithmetic.hpp:35
Definition arithmetic.hpp:45
Definition arithmetic.hpp:25