xref: /freebsd/contrib/llvm-project/libcxx/include/__utility/forward_like.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1bdd1243dSDimitry Andric // -*- C++ -*-
2bdd1243dSDimitry Andric //===----------------------------------------------------------------------===//
3bdd1243dSDimitry Andric //
4bdd1243dSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5bdd1243dSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
6bdd1243dSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7bdd1243dSDimitry Andric //
8bdd1243dSDimitry Andric //===----------------------------------------------------------------------===//
9bdd1243dSDimitry Andric 
10bdd1243dSDimitry Andric #ifndef _LIBCPP___UTILITY_FORWARD_LIKE_H
11bdd1243dSDimitry Andric #define _LIBCPP___UTILITY_FORWARD_LIKE_H
12bdd1243dSDimitry Andric 
13bdd1243dSDimitry Andric #include <__config>
14bdd1243dSDimitry Andric #include <__type_traits/conditional.h>
15bdd1243dSDimitry Andric #include <__type_traits/is_const.h>
16bdd1243dSDimitry Andric #include <__type_traits/is_reference.h>
17bdd1243dSDimitry Andric #include <__type_traits/remove_reference.h>
18bdd1243dSDimitry Andric 
19bdd1243dSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20bdd1243dSDimitry Andric #  pragma GCC system_header
21bdd1243dSDimitry Andric #endif
22bdd1243dSDimitry Andric 
23bdd1243dSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
24bdd1243dSDimitry Andric 
2506c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 23
26bdd1243dSDimitry Andric 
27bdd1243dSDimitry Andric template <class _Ap, class _Bp>
28bdd1243dSDimitry Andric using _CopyConst = _If<is_const_v<_Ap>, const _Bp, _Bp>;
29bdd1243dSDimitry Andric 
30bdd1243dSDimitry Andric template <class _Ap, class _Bp>
31bdd1243dSDimitry Andric using _OverrideRef = _If<is_rvalue_reference_v<_Ap>, remove_reference_t<_Bp>&&, _Bp&>;
32bdd1243dSDimitry Andric 
33bdd1243dSDimitry Andric template <class _Ap, class _Bp>
34bdd1243dSDimitry Andric using _ForwardLike = _OverrideRef<_Ap&&, _CopyConst<remove_reference_t<_Ap>, remove_reference_t<_Bp>>>;
35bdd1243dSDimitry Andric 
36bdd1243dSDimitry Andric template <class _Tp, class _Up>
37*0fca6ea1SDimitry Andric [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto
38*0fca6ea1SDimitry Andric forward_like(_LIBCPP_LIFETIMEBOUND _Up&& __ux) noexcept -> _ForwardLike<_Tp, _Up> {
39bdd1243dSDimitry Andric   return static_cast<_ForwardLike<_Tp, _Up>>(__ux);
40bdd1243dSDimitry Andric }
41bdd1243dSDimitry Andric 
4206c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 23
43bdd1243dSDimitry Andric 
44bdd1243dSDimitry Andric _LIBCPP_END_NAMESPACE_STD
45bdd1243dSDimitry Andric 
46bdd1243dSDimitry Andric #endif // _LIBCPP___UTILITY_FORWARD_LIKE_H
47