1050b064fSChristopher Di Bella // -*- C++ -*- 2050b064fSChristopher Di Bella //===----------------------------------------------------------------------===// 3050b064fSChristopher Di Bella // 4050b064fSChristopher Di Bella // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5050b064fSChristopher Di Bella // See https://llvm.org/LICENSE.txt for license information. 6050b064fSChristopher Di Bella // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7050b064fSChristopher Di Bella // 8050b064fSChristopher Di Bella //===----------------------------------------------------------------------===// 9050b064fSChristopher Di Bella 10050b064fSChristopher Di Bella #ifndef _LIBCPP___FUNCTIONAL_IDENTITY_H 11050b064fSChristopher Di Bella #define _LIBCPP___FUNCTIONAL_IDENTITY_H 12050b064fSChristopher Di Bella 13050b064fSChristopher Di Bella #include <__config> 1433de5a31SNikolas Klauser #include <__fwd/functional.h> 15b4ecfd3cSNikolas Klauser #include <__type_traits/integral_constant.h> 16ea2206d7SArthur O'Dwyer #include <__utility/forward.h> 17050b064fSChristopher Di Bella 18050b064fSChristopher Di Bella #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 19050b064fSChristopher Di Bella # pragma GCC system_header 20050b064fSChristopher Di Bella #endif 21050b064fSChristopher Di Bella 22050b064fSChristopher Di Bella _LIBCPP_BEGIN_NAMESPACE_STD 23050b064fSChristopher Di Bella 24b4ecfd3cSNikolas Klauser template <class _Tp> 25b4ecfd3cSNikolas Klauser struct __is_identity : false_type {}; 26b4ecfd3cSNikolas Klauser 2758d9ab70SNikolas Klauser struct __identity { 2858d9ab70SNikolas Klauser template <class _Tp> 29*17e0686aSNikolas Klauser [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&& operator()(_Tp&& __t) const _NOEXCEPT { 3058d9ab70SNikolas Klauser return std::forward<_Tp>(__t); 3158d9ab70SNikolas Klauser } 3258d9ab70SNikolas Klauser 3358d9ab70SNikolas Klauser using is_transparent = void; 3458d9ab70SNikolas Klauser }; 3558d9ab70SNikolas Klauser 36b4ecfd3cSNikolas Klauser template <> 37b4ecfd3cSNikolas Klauser struct __is_identity<__identity> : true_type {}; 38fdd089b5SZijunZhaoCCK template <> 39fdd089b5SZijunZhaoCCK struct __is_identity<reference_wrapper<__identity> > : true_type {}; 40fdd089b5SZijunZhaoCCK template <> 41fdd089b5SZijunZhaoCCK struct __is_identity<reference_wrapper<const __identity> > : true_type {}; 42b4ecfd3cSNikolas Klauser 434f15267dSNikolas Klauser #if _LIBCPP_STD_VER >= 20 44050b064fSChristopher Di Bella 45050b064fSChristopher Di Bella struct identity { 46050b064fSChristopher Di Bella template <class _Tp> 4783bc7b57SNikolas Klauser [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp&& operator()(_Tp&& __t) const noexcept { 4877a00c0dSLouis Dionne return std::forward<_Tp>(__t); 49050b064fSChristopher Di Bella } 50050b064fSChristopher Di Bella 51050b064fSChristopher Di Bella using is_transparent = void; 52050b064fSChristopher Di Bella }; 53b4ecfd3cSNikolas Klauser 54b4ecfd3cSNikolas Klauser template <> 55b4ecfd3cSNikolas Klauser struct __is_identity<identity> : true_type {}; 56fdd089b5SZijunZhaoCCK template <> 57fdd089b5SZijunZhaoCCK struct __is_identity<reference_wrapper<identity> > : true_type {}; 58fdd089b5SZijunZhaoCCK template <> 59fdd089b5SZijunZhaoCCK struct __is_identity<reference_wrapper<const identity> > : true_type {}; 60b4ecfd3cSNikolas Klauser 614f15267dSNikolas Klauser #endif // _LIBCPP_STD_VER >= 20 62050b064fSChristopher Di Bella 63050b064fSChristopher Di Bella _LIBCPP_END_NAMESPACE_STD 64050b064fSChristopher Di Bella 65050b064fSChristopher Di Bella #endif // _LIBCPP___FUNCTIONAL_IDENTITY_H 66