[libcxx] r338666 - Implement P0887: The identity metafunction
Marshall Clow via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 1 18:56:02 PDT 2018
Author: marshall
Date: Wed Aug 1 18:56:02 2018
New Revision: 338666
URL: http://llvm.org/viewvc/llvm-project?rev=338666&view=rev
Log:
Implement P0887: The identity metafunction
Added:
libcxx/trunk/test/std/utilities/meta/meta.trans/meta.trans.other/type_identity.pass.cpp
Modified:
libcxx/trunk/include/type_traits
Modified: libcxx/trunk/include/type_traits
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=338666&r1=338665&r2=338666&view=diff
==============================================================================
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Wed Aug 1 18:56:02 2018
@@ -75,6 +75,10 @@ namespace std
template <class T> struct remove_pointer;
template <class T> struct add_pointer;
+ template<class T> struct type_identity; // C++20
+ template<class T>
+ using type_identity_t = typename type_identity<T>::type; // C++20
+
// Integral properties:
template <class T> struct is_signed;
template <class T> struct is_unsigned;
@@ -1226,6 +1230,12 @@ template <class _Tp> struct _LIBCPP_TEMP
template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type;
#endif
+// type_identity
+#if _LIBCPP_STD_VER > 17
+template<class _Tp> struct type_identity { typedef _Tp type; };
+template<class _Tp> using type_identity_t = typename type_identity<_Tp>::type;
+#endif
+
// is_signed
template <class _Tp, bool = is_integral<_Tp>::value>
Added: libcxx/trunk/test/std/utilities/meta/meta.trans/meta.trans.other/type_identity.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/meta/meta.trans/meta.trans.other/type_identity.pass.cpp?rev=338666&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/meta/meta.trans/meta.trans.other/type_identity.pass.cpp (added)
+++ libcxx/trunk/test/std/utilities/meta/meta.trans/meta.trans.other/type_identity.pass.cpp Wed Aug 1 18:56:02 2018
@@ -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 <type_traits>
+
+#include "test_macros.h"
+
+template <class T>
+void test_type_identity()
+{
+ static_assert((std::is_same<typename std::type_identity<T>::type, T>::value), "");
+ static_assert((std::is_same< std::type_identity_t<T>, T>::value), "");
+}
+
+int main()
+{
+ test_type_identity<void>();
+ test_type_identity<int>();
+ test_type_identity<const volatile int>();
+ test_type_identity<int*>();
+ test_type_identity< int[3]>();
+ test_type_identity<const int[3]>();
+
+ test_type_identity<void (*)()>();
+ test_type_identity<int(int) const>();
+ test_type_identity<int(int) volatile>();
+ test_type_identity<int(int) &>();
+ test_type_identity<int(int) &&>();
+}
More information about the cfe-commits
mailing list