1fe6060f1SDimitry Andric // -*- C++ -*- 2fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 3fe6060f1SDimitry Andric // 4fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 6fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7fe6060f1SDimitry Andric // 8fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 9fe6060f1SDimitry Andric 10fe6060f1SDimitry Andric #ifndef _LIBCPP___FUNCTIONAL_IDENTITY_H 11fe6060f1SDimitry Andric #define _LIBCPP___FUNCTIONAL_IDENTITY_H 12fe6060f1SDimitry Andric 13fe6060f1SDimitry Andric #include <__config> 14*0fca6ea1SDimitry Andric #include <__fwd/functional.h> 1506c3fb27SDimitry Andric #include <__type_traits/integral_constant.h> 1681ad6265SDimitry Andric #include <__utility/forward.h> 17fe6060f1SDimitry Andric 18fe6060f1SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 19fe6060f1SDimitry Andric # pragma GCC system_header 20fe6060f1SDimitry Andric #endif 21fe6060f1SDimitry Andric 22fe6060f1SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 23fe6060f1SDimitry Andric 2406c3fb27SDimitry Andric template <class _Tp> 2506c3fb27SDimitry Andric struct __is_identity : false_type {}; 2606c3fb27SDimitry Andric 2781ad6265SDimitry Andric struct __identity { 2881ad6265SDimitry Andric template <class _Tp> 2906c3fb27SDimitry Andric _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&& operator()(_Tp&& __t) const _NOEXCEPT { 3081ad6265SDimitry Andric return std::forward<_Tp>(__t); 3181ad6265SDimitry Andric } 3281ad6265SDimitry Andric 3381ad6265SDimitry Andric using is_transparent = void; 3481ad6265SDimitry Andric }; 3581ad6265SDimitry Andric 3606c3fb27SDimitry Andric template <> 3706c3fb27SDimitry Andric struct __is_identity<__identity> : true_type {}; 38cb14a3feSDimitry Andric template <> 39cb14a3feSDimitry Andric struct __is_identity<reference_wrapper<__identity> > : true_type {}; 40cb14a3feSDimitry Andric template <> 41cb14a3feSDimitry Andric struct __is_identity<reference_wrapper<const __identity> > : true_type {}; 4206c3fb27SDimitry Andric 4306c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20 44fe6060f1SDimitry Andric 45fe6060f1SDimitry Andric struct identity { 46fe6060f1SDimitry Andric template <class _Tp> 47*0fca6ea1SDimitry Andric [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp&& operator()(_Tp&& __t) const noexcept { 485f757f3fSDimitry Andric return std::forward<_Tp>(__t); 49fe6060f1SDimitry Andric } 50fe6060f1SDimitry Andric 51fe6060f1SDimitry Andric using is_transparent = void; 52fe6060f1SDimitry Andric }; 5306c3fb27SDimitry Andric 5406c3fb27SDimitry Andric template <> 5506c3fb27SDimitry Andric struct __is_identity<identity> : true_type {}; 56cb14a3feSDimitry Andric template <> 57cb14a3feSDimitry Andric struct __is_identity<reference_wrapper<identity> > : true_type {}; 58cb14a3feSDimitry Andric template <> 59cb14a3feSDimitry Andric struct __is_identity<reference_wrapper<const identity> > : true_type {}; 6006c3fb27SDimitry Andric 6106c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 20 62fe6060f1SDimitry Andric 63fe6060f1SDimitry Andric _LIBCPP_END_NAMESPACE_STD 64fe6060f1SDimitry Andric 65fe6060f1SDimitry Andric #endif // _LIBCPP___FUNCTIONAL_IDENTITY_H 66