Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
modulus.hpp
Go to the documentation of this file.
1// Copyright 2026, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_MODULUS_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_MODULUS_HPP_
7
8// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
9// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
10
11// IWYU pragma: private, include <functional>
12// IWYU pragma: friend "stdlib_detail/.*"
13
19
20namespace std {
21
22/// @brief Function object for performing modulus.
23/// @tparam T The type of the values
24/// @note This class contains the member types @c result_type, @c first_argument type, and @c second_argument type.
25/// These aliases have been deprecated in C++17 and removed in C++20.
26template <class T = void>
27class modulus {
28 public:
29 /// @brief Result type of invoking this object
30 using result_type = T;
31 /// @brief Type of the first value to modulus
33 /// @brief Type of the second value to modulus
35
36 /// @brief Returns the remainder of the first value divided by second value
37 /// @tparam U Template parameter to enable constraints.
38 /// @param lhs The first value to divide
39 /// @param rhs The second value to divide
40 /// Produces the result of invoking @c operator% on @c lhs and @c rhs.
41 template <class U = T, arene::base::constraints<std::enable_if_t<!is_integral_v<U>>> = nullptr>
42 constexpr auto operator()(T const& lhs, T const& rhs) const
43 noexcept(noexcept(std::declval<T&>() % std::declval<T&>())) -> T {
44 return lhs % rhs;
45 }
46
47 /// @brief Returns the remainder of the first value divided by second value
48 /// @tparam U Template parameter to enable constraints.
49 /// @param lhs The first value to divide
50 /// @param rhs The second value to divide
51 /// Produces the result of invoking @c operator% on @c lhs and @c rhs.
52 ///
53 /// @note This overload explicitly casts the result of the computation to the type @c T. This avoids any warning for
54 /// implicit conversion (present on gcc8).
55 template <class U = T, arene::base::constraints<std::enable_if_t<is_integral_v<U>>> = nullptr>
56 constexpr auto operator()(T const& lhs, T const& rhs) const
57 noexcept(noexcept(std::declval<T&>() % std::declval<T&>())) -> T {
58 return static_cast<T>(lhs % rhs);
59 }
60};
61
62/// @brief Function object that can be invoked for modulus, specialized for type deduction
63template <>
64class modulus<void> {
65 public:
66 /// @brief Denotes that this is a transparent function object type
67 using is_transparent = void;
68
69 // parasoft-begin-suppress AUTOSAR-M5_0_4-a "Function return type is specified by the C++ Standard"
70 /// @brief Returns the remainder of the first value divided by second value
71 /// @tparam T The first type
72 /// @tparam U The second type
73 /// @param lhs The first value to divide
74 /// @param rhs The second value to divide
75 /// @return Returns the result of invoking @c operator% on @c lhs and @c rhs
76 template <class T, class U>
77 constexpr auto operator()(T&& lhs, U&& rhs) const
79 -> decltype(std::forward<T>(lhs) % std::forward<U>(rhs)) {
80 return std::forward<T>(lhs) % std::forward<U>(rhs);
81 }
82 // parasoft-end-suppress AUTOSAR-M5_0_4-a
83};
84
85} // namespace std
86
87#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_MODULUS_HPP_
constexpr auto operator()(T &&lhs, U &&rhs) const noexcept(noexcept(std::forward< T >(std::declval< T & >()) % std::forward< U >(std::declval< U & >()))) ->
Returns the remainder of the first value divided by second value.
Definition modulus.hpp:77
void is_transparent
Denotes that this is a transparent function object type.
Definition modulus.hpp:67
Function object for performing modulus.
Definition modulus.hpp:27
T second_argument_type
Type of the second value to modulus.
Definition modulus.hpp:34
T first_argument_type
Type of the first value to modulus.
Definition modulus.hpp:32
constexpr auto operator()(T const &lhs, T const &rhs) const noexcept(noexcept(std::declval< T & >() % std::declval< T & >())) -> T
Returns the remainder of the first value divided by second value.
Definition modulus.hpp:42
T result_type
Result type of invoking this object.
Definition modulus.hpp:30
Public export header for the constraints subpackage.
STL namespace.
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...
constexpr auto forward(remove_reference_t< T > &value) noexcept -> T &&
Cast a value to an rvalue if T is an rvalue or rvalue reference, otherwise forward an lvalue referenc...
Definition forward.hpp:24