From cf49ccd0e51c2019325908e18e0ae63e05c14cad Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Thu, 2 Aug 2018 01:56:02 +0000 Subject: [PATCH] Implement P0887: The identity metafunction llvm-svn: 338666 --- libcxx/include/type_traits | 10 ++++++ .../meta.trans.other/type_identity.pass.cpp | 40 ++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/type_identity.pass.cpp diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits index 30bfb16..e413d26 100644 --- a/libcxx/include/type_traits +++ b/libcxx/include/type_traits @@ -75,6 +75,10 @@ namespace std template struct remove_pointer; template struct add_pointer; + template struct type_identity; // C++20 + template + using type_identity_t = typename type_identity::type; // C++20 + // Integral properties: template struct is_signed; template struct is_unsigned; @@ -1226,6 +1230,12 @@ template struct _LIBCPP_TEMPLATE_VIS add_pointer template using add_pointer_t = typename add_pointer<_Tp>::type; #endif +// type_identity +#if _LIBCPP_STD_VER > 17 +template struct type_identity { typedef _Tp type; }; +template using type_identity_t = typename type_identity<_Tp>::type; +#endif + // is_signed template ::value> diff --git a/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/type_identity.pass.cpp b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/type_identity.pass.cpp new file mode 100644 index 0000000..0799866 --- /dev/null +++ b/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/type_identity.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 + +// type_traits + +// type_identity + +#include + +#include "test_macros.h" + +template +void test_type_identity() +{ + static_assert((std::is_same::type, T>::value), ""); + static_assert((std::is_same< std::type_identity_t, T>::value), ""); +} + +int main() +{ + test_type_identity(); + test_type_identity(); + test_type_identity(); + test_type_identity(); + test_type_identity< int[3]>(); + test_type_identity(); + + test_type_identity(); + test_type_identity(); + test_type_identity(); + test_type_identity(); + test_type_identity(); +} -- 2.7.4