xref: /freebsd/contrib/llvm-project/libcxx/include/__utility/forward_like.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
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_LIKE_H
11 #define _LIBCPP___UTILITY_FORWARD_LIKE_H
12 
13 #include <__config>
14 #include <__type_traits/conditional.h>
15 #include <__type_traits/is_const.h>
16 #include <__type_traits/is_reference.h>
17 #include <__type_traits/remove_reference.h>
18 
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 #  pragma GCC system_header
21 #endif
22 
23 _LIBCPP_BEGIN_NAMESPACE_STD
24 
25 #if _LIBCPP_STD_VER >= 23
26 
27 template <class _Ap, class _Bp>
28 using _CopyConst = _If<is_const_v<_Ap>, const _Bp, _Bp>;
29 
30 template <class _Ap, class _Bp>
31 using _OverrideRef = _If<is_rvalue_reference_v<_Ap>, remove_reference_t<_Bp>&&, _Bp&>;
32 
33 template <class _Ap, class _Bp>
34 using _ForwardLike = _OverrideRef<_Ap&&, _CopyConst<remove_reference_t<_Ap>, remove_reference_t<_Bp>>>;
35 
36 template <class _Tp, class _Up>
37 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto
38 forward_like(_LIBCPP_LIFETIMEBOUND _Up&& __ux) noexcept -> _ForwardLike<_Tp, _Up> {
39   return static_cast<_ForwardLike<_Tp, _Up>>(__ux);
40 }
41 
42 #endif // _LIBCPP_STD_VER >= 23
43 
44 _LIBCPP_END_NAMESPACE_STD
45 
46 #endif // _LIBCPP___UTILITY_FORWARD_LIKE_H
47