From ee896276f6483832d45c9280915367c825c32098 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 2 Jul 2018 22:05:08 +0100 Subject: [PATCH] P0887R1 The identity metafunction * include/std/type_traits (type_identity, type_identity_t): Define for C++2a. * testsuite/20_util/type_identity/requirements/alias_decl.cc: New. * testsuite/20_util/type_identity/requirements/ explicit_instantiation.cc:New. * testsuite/20_util/type_identity/requirements/typedefs.cc: New. From-SVN: r262319 --- libstdc++-v3/ChangeLog | 8 ++ libstdc++-v3/include/std/type_traits | 7 ++ .../type_identity/requirements/alias_decl.cc | 35 +++++++ .../requirements/explicit_instantiation.cc | 29 ++++++ .../type_identity/requirements/typedefs.cc | 94 +++++++++++++++++++ 5 files changed, 173 insertions(+) create mode 100644 libstdc++-v3/testsuite/20_util/type_identity/requirements/alias_decl.cc create mode 100644 libstdc++-v3/testsuite/20_util/type_identity/requirements/explicit_instantiation.cc create mode 100644 libstdc++-v3/testsuite/20_util/type_identity/requirements/typedefs.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b2958e43745..c6e84be4602 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,13 @@ 2018-07-02 Jonathan Wakely + P0887R1 The identity metafunction + * include/std/type_traits (type_identity, type_identity_t): Define + for C++2a. + * testsuite/20_util/type_identity/requirements/alias_decl.cc: New. + * testsuite/20_util/type_identity/requirements/ + explicit_instantiation.cc:New. + * testsuite/20_util/type_identity/requirements/typedefs.cc: New. + * include/bits/regex.h (sub_match::operator string_type): Call str(). (sub_match::compare): Use _M_str() instead of str(). (sub_match::_M_compare): New public function. diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 0c7e97286ca..b2d3380f024 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2996,6 +2996,13 @@ template template using remove_cvref_t = __remove_cvref_t<_Tp>; + /// Identity metafunction. + template + struct type_identity { using type = _Tp; }; + + template + using type_identity_t = typename type_identity<_Tp>::type; + #endif // C++2a _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/testsuite/20_util/type_identity/requirements/alias_decl.cc b/libstdc++-v3/testsuite/20_util/type_identity/requirements/alias_decl.cc new file mode 100644 index 00000000000..6729d118273 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/type_identity/requirements/alias_decl.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } +// +#include + +using namespace std; + +template> + struct test; // undefined + +template + struct test : std::true_type { }; + +static_assert( test{}, "type_identity_t" ); +static_assert( test{}, "type_identity_t" ); +static_assert( test{}, "type_identity_t" ); +static_assert( test{}, "type_identity_t" ); +static_assert( test{}, "type_identity_t" ); diff --git a/libstdc++-v3/testsuite/20_util/type_identity/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/type_identity/requirements/explicit_instantiation.cc new file mode 100644 index 00000000000..07387e719ce --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/type_identity/requirements/explicit_instantiation.cc @@ -0,0 +1,29 @@ +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include + +namespace std +{ + typedef short test_type; + template struct type_identity; +} diff --git a/libstdc++-v3/testsuite/20_util/type_identity/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/type_identity/requirements/typedefs.cc new file mode 100644 index 00000000000..77f0cba9b4c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/type_identity/requirements/typedefs.cc @@ -0,0 +1,94 @@ +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +template::type> + struct test; // undefined + +template + struct test : std::true_type { }; + +enum test_enum { }; +struct test_class { }; +struct incomplete_class; + +void test01() +{ + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + +#ifdef _GLIBCXX_USE_WCHAR_T + static_assert(test::value, "" ); +#endif + + // Pointers + static_assert(test::value, ""); + static_assert(test::value, ""); + // References + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + // Arrays + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + + // Functions + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + + // Abominable function types + static_assert(test::value, ""); + static_assert(test::value, ""); + + // Pointers to members + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + static_assert(test::value, ""); + +#ifndef __STRICT_ANSI__ + // GNU Extensions. +#ifdef _GLIBCXX_USE_INT128 + static_assert(test::value, ""); + static_assert(test::value, ""); +#endif +#endif +} -- 2.30.2