forward_like.hpp
Go to the documentation of this file.
1 // Copyright 2023-2024 Ekumen, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef BELUGA_UTILITY_FORWARD_LIKE_HPP
16 #define BELUGA_UTILITY_FORWARD_LIKE_HPP
17 
18 namespace beluga {
19 
21 
32 template <class T, class U>
33 [[nodiscard]] constexpr auto&& forward_like(U&& value) noexcept {
34  constexpr bool is_adding_const = std::is_const_v<std::remove_reference_t<T>>; // NOLINT
35  if constexpr (std::is_lvalue_reference_v<T&&>) {
36  if constexpr (is_adding_const) {
37  return std::as_const(value);
38  } else {
39  return value;
40  }
41  } else {
42  if constexpr (is_adding_const) {
43  return std::move(std::as_const(value));
44  } else {
45  return std::forward<U>(value);
46  }
47  }
48 }
49 
50 } // namespace beluga
51 
52 #endif
beluga::forward_like
constexpr auto && forward_like(U &&value) noexcept
Returns a reference to a value which has similar properties to T&&.
Definition: forward_like.hpp:33
beluga
The main Beluga namespace.
Definition: 3d_embedding.hpp:21


beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53