forward.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. #ifndef _LIBCPP___UTILITY_FORWARD_H
  10. #define _LIBCPP___UTILITY_FORWARD_H
  11. #include <__config>
  12. #include <__type_traits/is_reference.h>
  13. #include <__type_traits/remove_reference.h>
  14. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  15. # pragma GCC system_header
  16. #endif
  17. _LIBCPP_BEGIN_NAMESPACE_STD
  18. template <class _Tp>
  19. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&&
  20. forward(_LIBCPP_LIFETIMEBOUND __libcpp_remove_reference_t<_Tp>& __t) _NOEXCEPT {
  21. return static_cast<_Tp&&>(__t);
  22. }
  23. template <class _Tp>
  24. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&&
  25. forward(_LIBCPP_LIFETIMEBOUND __libcpp_remove_reference_t<_Tp>&& __t) _NOEXCEPT {
  26. static_assert(!is_lvalue_reference<_Tp>::value, "cannot forward an rvalue as an lvalue");
  27. return static_cast<_Tp&&>(__t);
  28. }
  29. _LIBCPP_END_NAMESPACE_STD
  30. #endif // _LIBCPP___UTILITY_FORWARD_H