1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___UTILITY_FORWARD_H
11#define _LIBCPP___UTILITY_FORWARD_H
12
13#include <__config>
14#include <__type_traits/is_reference.h>
15#include <__type_traits/remove_reference.h>
16
17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18#  pragma GCC system_header
19#endif
20
21_LIBCPP_BEGIN_NAMESPACE_STD
22
23template <class _Tp>
24_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&&
25forward(_LIBCPP_LIFETIMEBOUND __libcpp_remove_reference_t<_Tp>& __t) _NOEXCEPT {
26  return static_cast<_Tp&&>(__t);
27}
28
29template <class _Tp>
30_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&&
31forward(_LIBCPP_LIFETIMEBOUND __libcpp_remove_reference_t<_Tp>&& __t) _NOEXCEPT {
32  static_assert(!is_lvalue_reference<_Tp>::value, "cannot forward an rvalue as an lvalue");
33  return static_cast<_Tp&&>(__t);
34}
35
36_LIBCPP_END_NAMESPACE_STD
37
38#endif // _LIBCPP___UTILITY_FORWARD_H
39