mirror of git://gcc.gnu.org/git/gcc.git
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
This commit is contained in:
parent
e112d53aca
commit
ee896276f6
|
|
@ -1,5 +1,13 @@
|
||||||
2018-07-02 Jonathan Wakely <jwakely@redhat.com>
|
2018-07-02 Jonathan Wakely <jwakely@redhat.com>
|
||||||
|
|
||||||
|
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().
|
* include/bits/regex.h (sub_match::operator string_type): Call str().
|
||||||
(sub_match::compare): Use _M_str() instead of str().
|
(sub_match::compare): Use _M_str() instead of str().
|
||||||
(sub_match::_M_compare): New public function.
|
(sub_match::_M_compare): New public function.
|
||||||
|
|
|
||||||
|
|
@ -2996,6 +2996,13 @@ template <typename _From, typename _To>
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
using remove_cvref_t = __remove_cvref_t<_Tp>;
|
using remove_cvref_t = __remove_cvref_t<_Tp>;
|
||||||
|
|
||||||
|
/// Identity metafunction.
|
||||||
|
template<typename _Tp>
|
||||||
|
struct type_identity { using type = _Tp; };
|
||||||
|
|
||||||
|
template<typename _Tp>
|
||||||
|
using type_identity_t = typename type_identity<_Tp>::type;
|
||||||
|
|
||||||
#endif // C++2a
|
#endif // C++2a
|
||||||
|
|
||||||
_GLIBCXX_END_NAMESPACE_VERSION
|
_GLIBCXX_END_NAMESPACE_VERSION
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
// <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// { dg-options "-std=gnu++2a" }
|
||||||
|
// { dg-do compile { target c++2a } }
|
||||||
|
//
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
template<typename T, typename = std::type_identity_t<T>>
|
||||||
|
struct test; // undefined
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct test<T, T> : std::true_type { };
|
||||||
|
|
||||||
|
static_assert( test<const int>{}, "type_identity_t<const int>" );
|
||||||
|
static_assert( test<volatile int>{}, "type_identity_t<volatile int>" );
|
||||||
|
static_assert( test<unsigned>{}, "type_identity_t<unsigned>" );
|
||||||
|
static_assert( test<char>{}, "type_identity_t<char>" );
|
||||||
|
static_assert( test<signed char>{}, "type_identity_t<signed char>" );
|
||||||
|
|
@ -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
|
||||||
|
// <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// { dg-options "-std=gnu++2a" }
|
||||||
|
// { dg-do compile { target c++2a } }
|
||||||
|
|
||||||
|
// NB: This file is for testing type_traits with NO OTHER INCLUDES.
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
typedef short test_type;
|
||||||
|
template struct type_identity<test_type>;
|
||||||
|
}
|
||||||
|
|
@ -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
|
||||||
|
// <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// { dg-options "-std=gnu++2a" }
|
||||||
|
// { dg-do compile { target c++2a } }
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
template<typename T, typename = typename std::type_identity<T>::type>
|
||||||
|
struct test; // undefined
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct test<T, T> : std::true_type { };
|
||||||
|
|
||||||
|
enum test_enum { };
|
||||||
|
struct test_class { };
|
||||||
|
struct incomplete_class;
|
||||||
|
|
||||||
|
void test01()
|
||||||
|
{
|
||||||
|
static_assert(test<float>::value, "");
|
||||||
|
static_assert(test<const unsigned int>::value, "");
|
||||||
|
static_assert(test<const unsigned int>::value, "");
|
||||||
|
static_assert(test<volatile unsigned int>::value, "");
|
||||||
|
static_assert(test<const volatile unsigned int>::value, "");
|
||||||
|
static_assert(test<const unsigned char>::value, "");
|
||||||
|
|
||||||
|
#ifdef _GLIBCXX_USE_WCHAR_T
|
||||||
|
static_assert(test<volatile wchar_t>::value, "" );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Pointers
|
||||||
|
static_assert(test<void*>::value, "");
|
||||||
|
static_assert(test<long*>::value, "");
|
||||||
|
// References
|
||||||
|
static_assert(test<short&>::value, "");
|
||||||
|
static_assert(test<char&&>::value, "");
|
||||||
|
static_assert(test<int*&>::value, "");
|
||||||
|
// Arrays
|
||||||
|
static_assert(test<int[]>::value, "");
|
||||||
|
static_assert(test<int[2]>::value, "");
|
||||||
|
static_assert(test<int[2][3]>::value, "");
|
||||||
|
static_assert(test<int(*)[2]>::value, "");
|
||||||
|
static_assert(test<int(&)[2]>::value, "");
|
||||||
|
|
||||||
|
static_assert(test<test_enum>::value, "");
|
||||||
|
static_assert(test<test_class>::value, "");
|
||||||
|
static_assert(test<incomplete_class>::value, "");
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
static_assert(test<void(*)()>::value, "");
|
||||||
|
static_assert(test<int(*)(int) noexcept>::value, "");
|
||||||
|
static_assert(test<void(&)()>::value, "");
|
||||||
|
static_assert(test<long(&)(long) noexcept>::value, "");
|
||||||
|
static_assert(test<void()>::value, "");
|
||||||
|
static_assert(test<int(int, int)>::value, "");
|
||||||
|
static_assert(test<void() noexcept>::value, "");
|
||||||
|
static_assert(test<int(int, int) noexcept>::value, "");
|
||||||
|
|
||||||
|
// Abominable function types
|
||||||
|
static_assert(test<void(int) const>::value, "");
|
||||||
|
static_assert(test<void(int) const volatile>::value, "");
|
||||||
|
|
||||||
|
// Pointers to members
|
||||||
|
static_assert(test<int incomplete_class::*>::value, "");
|
||||||
|
static_assert(test<void(incomplete_class::*)(int)>::value, "");
|
||||||
|
static_assert(test<void(incomplete_class::*)(int) noexcept>::value, "");
|
||||||
|
static_assert(test<void(incomplete_class::*)() const>::value, "");
|
||||||
|
static_assert(test<void(incomplete_class::*)() &>::value, "");
|
||||||
|
static_assert(test<void(incomplete_class::*)() &&>::value, "");
|
||||||
|
static_assert(test<void(incomplete_class::*)() volatile &&>::value, "");
|
||||||
|
|
||||||
|
#ifndef __STRICT_ANSI__
|
||||||
|
// GNU Extensions.
|
||||||
|
#ifdef _GLIBCXX_USE_INT128
|
||||||
|
static_assert(test<unsigned __int128>::value, "");
|
||||||
|
static_assert(test<unsigned __int128>::value, "");
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue