Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
forward.hpp
Go to the documentation of this file.
1// Copyright 2024, 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_FORWARD_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_FORWARD_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 <utility>
12// IWYU pragma: friend "stdlib_detail/.*"
13
14#include "stdlib/include/stdlib_detail/is_lvalue_reference.hpp"
15#include "stdlib/include/stdlib_detail/remove_reference.hpp"
16
17namespace std {
18// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
19/// @brief Cast a value to an rvalue if @c T is an rvalue or rvalue reference, otherwise forward an lvalue reference
20/// @tparam T The type of the value
21/// @param value The value to cast
22/// @return The input reference cast to an rvalue
23template <typename T>
24constexpr auto forward(remove_reference_t<T>& value) noexcept -> T&& {
25 return static_cast<T&&>(value);
26}
27// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
28
29// parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "False positive: Value is forwarded as appropriate"
30// parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "False positive: Value is forwarded as appropriate"
31// parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "False positive: Value is forwarded as appropriate"
32// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
33/// @brief Cast a value to an rvalue if @c T is an rvalue or rvalue reference, otherwise forward an lvalue reference
34/// @tparam T The type of the value
35/// @param value The value to cast
36/// @return The input reference cast to an rvalue
37template <typename T>
38constexpr auto forward(remove_reference_t<T>&& value) noexcept -> T&& {
39 static_assert(!is_lvalue_reference_v<T>, "Cannot forward an rvalue as an lvalue");
40 return static_cast<T&&>(value);
41}
42// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
43// parasoft-end-suppress AUTOSAR-A12_8_4-a-2
44// parasoft-end-suppress AUTOSAR-A8_4_5-a-2
45// parasoft-end-suppress AUTOSAR-A8_4_6-a-2
46
47} // namespace std
48
49#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_FORWARD_HPP_
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:38
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
constexpr auto operator()(::arene::base::result< void, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >()))) -> std::size_t
Calculate the hash of a result.
Definition result.hpp:1827