tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
forward_like.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_UTILITY_FORWARD_LIKE_HPP
4#define TETL_UTILITY_FORWARD_LIKE_HPP
5
10#include <etl/_utility/move.hpp>
11
12namespace etl {
13
14template <typename T, typename U>
15[[nodiscard]] constexpr auto forward_like(U&& x) noexcept -> auto&&
16{
17 constexpr auto isAddingConst = etl::is_const_v<etl::remove_reference_t<T>>;
18
19 if constexpr (etl::is_lvalue_reference_v<T&&>) {
20 if constexpr (isAddingConst) {
21 return etl::as_const(x);
22 } else {
23 return static_cast<U&>(x);
24 }
25 } else {
26 if constexpr (isAddingConst) {
27 return etl::move(etl::as_const(x));
28 } else {
29 return etl::move(x);
30 }
31 }
32}
33
34} // namespace etl
35
36#endif // TETL_UTILITY_FORWARD_LIKE_HPP
constexpr auto move(InputIt first, InputIt last, OutputIt destination) -> OutputIt
Moves the elements in the range [first, last), to another range beginning at destination,...
Definition move.hpp:26
Definition adjacent_find.hpp:8
constexpr auto as_const(T &t) noexcept -> add_const_t< T > &
Forms lvalue reference to const type of t.
Definition as_const.hpp:12
constexpr bool is_lvalue_reference_v
Definition is_lvalue_reference.hpp:20
constexpr bool is_const_v
Definition is_const.hpp:20
constexpr auto forward_like(U &&x) noexcept -> auto &&
Definition forward_like.hpp:15