[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / libc / src / __support / CPP / utility / forward.h
blob891097ec96d545d4b7d49a4f9cdc99f3b5338e97
1 //===-- forward utility -----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_FORWARD_H
9 #define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_FORWARD_H
11 #include "src/__support/CPP/type_traits/is_lvalue_reference.h"
12 #include "src/__support/CPP/type_traits/remove_reference.h"
13 #include "src/__support/macros/attributes.h"
15 namespace LIBC_NAMESPACE::cpp {
17 // forward
18 template <typename T>
19 LIBC_INLINE constexpr T &&forward(remove_reference_t<T> &value) {
20 return static_cast<T &&>(value);
23 template <typename T>
24 LIBC_INLINE constexpr T &&forward(remove_reference_t<T> &&value) {
25 static_assert(!is_lvalue_reference_v<T>,
26 "cannot forward an rvalue as an lvalue");
27 return static_cast<T &&>(value);
30 } // namespace LIBC_NAMESPACE::cpp
32 #endif // LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_FORWARD_H