| 1 |
/// \file |
| 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 |
|
| 20 |
namespace ranges |
| 21 |
{ |
| 22 |
/// \addtogroup group-functional |
| 23 |
/// @{ |
| 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 |
|
| 44 |
struct multiplies |
| 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 |
|
| 54 |
struct bitwise_or |
| 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> |
| 65 |
struct convert_to |
| 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 |
} |
| 83 |
/// \overload |
| 84 |
constexpr T const & operator()(T const & t) const |
| 85 |
{ |
| 86 |
return t; |
| 87 |
} |
| 88 |
/// \overload |
| 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 |
{}; |
| 107 |
/// @} |
| 108 |
} // namespace ranges |
| 109 |
|
| 110 |
#include <range/v3/detail/epilogue.hpp> |
| 111 |
|
| 112 |
#endif |