mirror of git://gcc.gnu.org/git/gcc.git
type_traits: Implement is_same, add_reference and remove_reference.
2004-12-08 Paolo Carlini <pcarlini@suse.de> * include/tr1/type_traits: Implement is_same, add_reference and remove_reference. * testsuite/testsuite_tr1.h (test_relationship): New. * testsuite/tr1/4_metaprogramming/reference_modifications/ add_reference.cc: New. * testsuite/tr1/4_metaprogramming/reference_modifications/ remove_reference.cc: Likewise. * testsuite/tr1/4_metaprogramming/relationships_between_types/ is_same/is_same.cc: Likewise. * testsuite/tr1/4_metaprogramming/relationships_between_types/ is_same/typedefs.cc: Likewise. * testsuite/tr1/4_metaprogramming/type_properties/is_const/ is_const.cc: Minor tweaks. * testsuite/tr1/4_metaprogramming/type_properties/is_volatile/ is_volatile.cc: Likewise. From-SVN: r91907
This commit is contained in:
parent
ce5e944cb4
commit
d63a0e228c
|
|
@ -1,3 +1,22 @@
|
||||||
|
2004-12-08 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
|
||||||
|
* include/tr1/type_traits: Implement is_same, add_reference and
|
||||||
|
remove_reference.
|
||||||
|
* testsuite/testsuite_tr1.h (test_relationship): New.
|
||||||
|
* testsuite/tr1/4_metaprogramming/reference_modifications/
|
||||||
|
add_reference.cc: New.
|
||||||
|
* testsuite/tr1/4_metaprogramming/reference_modifications/
|
||||||
|
remove_reference.cc: Likewise.
|
||||||
|
* testsuite/tr1/4_metaprogramming/relationships_between_types/
|
||||||
|
is_same/is_same.cc: Likewise.
|
||||||
|
* testsuite/tr1/4_metaprogramming/relationships_between_types/
|
||||||
|
is_same/typedefs.cc: Likewise.
|
||||||
|
|
||||||
|
* testsuite/tr1/4_metaprogramming/type_properties/is_const/
|
||||||
|
is_const.cc: Minor tweaks.
|
||||||
|
* testsuite/tr1/4_metaprogramming/type_properties/is_volatile/
|
||||||
|
is_volatile.cc: Likewise.
|
||||||
|
|
||||||
2004-12-08 David Edelsohn <edelsohn@gnu.org>
|
2004-12-08 David Edelsohn <edelsohn@gnu.org>
|
||||||
|
|
||||||
* Makefile.am (AM_MAKEFLAGS): Remove duplicate LIBCFLAGS and
|
* Makefile.am (AM_MAKEFLAGS): Remove duplicate LIBCFLAGS and
|
||||||
|
|
|
||||||
|
|
@ -240,8 +240,13 @@ namespace tr1
|
||||||
struct extent;
|
struct extent;
|
||||||
|
|
||||||
/// @brief relationships between types [4.6].
|
/// @brief relationships between types [4.6].
|
||||||
template<typename _Tp, typename _Up>
|
template<typename, typename>
|
||||||
struct is_same;
|
struct is_same
|
||||||
|
: public false_type { };
|
||||||
|
|
||||||
|
template<typename _Tp>
|
||||||
|
struct is_same<_Tp, _Tp>
|
||||||
|
: public true_type { };
|
||||||
|
|
||||||
template<typename _From, typename _To>
|
template<typename _From, typename _To>
|
||||||
struct is_convertible;
|
struct is_convertible;
|
||||||
|
|
@ -270,10 +275,28 @@ namespace tr1
|
||||||
|
|
||||||
/// @brief reference modifications [4.7.2].
|
/// @brief reference modifications [4.7.2].
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
struct remove_reference;
|
struct remove_reference
|
||||||
|
{
|
||||||
|
typedef _Tp type;
|
||||||
|
};
|
||||||
|
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
struct add_reference;
|
struct remove_reference<_Tp&>
|
||||||
|
{
|
||||||
|
typedef _Tp type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename _Tp>
|
||||||
|
struct add_reference
|
||||||
|
{
|
||||||
|
typedef _Tp& type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename _Tp>
|
||||||
|
struct add_reference<_Tp&>
|
||||||
|
{
|
||||||
|
typedef _Tp& type;
|
||||||
|
};
|
||||||
|
|
||||||
/// @brief array modififications [4.7.3].
|
/// @brief array modififications [4.7.3].
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
|
|
|
||||||
|
|
@ -41,13 +41,13 @@ namespace __gnu_test
|
||||||
{
|
{
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
ret &= Category<Type>::value == Tv;
|
ret &= Category<Type>::value == Tv;
|
||||||
ret &= Category<Type const>::value == Tv;
|
ret &= Category<const Type>::value == Tv;
|
||||||
ret &= Category<Type volatile>::value == Tv;
|
ret &= Category<volatile Type>::value == Tv;
|
||||||
ret &= Category<Type const volatile>::value == Tv;
|
ret &= Category<const volatile Type>::value == Tv;
|
||||||
ret &= Category<Type>::type::value == Tv;
|
ret &= Category<Type>::type::value == Tv;
|
||||||
ret &= Category<Type const>::type::value == Tv;
|
ret &= Category<const Type>::type::value == Tv;
|
||||||
ret &= Category<Type volatile>::type::value == Tv;
|
ret &= Category<volatile Type>::type::value == Tv;
|
||||||
ret &= Category<Type const volatile>::type::value == Tv;
|
ret &= Category<const volatile Type>::type::value == Tv;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,11 +62,22 @@ namespace __gnu_test
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<template<typename, typename> class Relationship,
|
||||||
|
typename Type1, typename Type2, bool Tv>
|
||||||
|
bool
|
||||||
|
test_relationship()
|
||||||
|
{
|
||||||
|
bool ret = true;
|
||||||
|
ret &= Relationship<Type1, Type2>::value == Tv;
|
||||||
|
ret &= Relationship<Type1, Type2>::type::value == Tv;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
// Test types.
|
// Test types.
|
||||||
class ClassType { };
|
class ClassType { };
|
||||||
typedef ClassType const cClassType;
|
typedef const ClassType cClassType;
|
||||||
typedef ClassType volatile vClassType;
|
typedef volatile ClassType vClassType;
|
||||||
typedef ClassType const volatile cvClassType;
|
typedef const volatile ClassType cvClassType;
|
||||||
}; // namespace __gnu_test
|
}; // namespace __gnu_test
|
||||||
|
|
||||||
#endif // _GLIBCXX_TESTSUITE_TR1_H
|
#endif // _GLIBCXX_TESTSUITE_TR1_H
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
// 2004-12-08 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
//
|
||||||
|
// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free
|
||||||
|
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||||
|
// USA.
|
||||||
|
|
||||||
|
// 4.7.2 Reference modifications
|
||||||
|
|
||||||
|
#include <tr1/type_traits>
|
||||||
|
#include <testsuite_hooks.h>
|
||||||
|
#include <testsuite_tr1.h>
|
||||||
|
|
||||||
|
void test01()
|
||||||
|
{
|
||||||
|
bool test __attribute__((unused)) = true;
|
||||||
|
using std::tr1::add_reference;
|
||||||
|
using std::tr1::is_same;
|
||||||
|
using namespace __gnu_test;
|
||||||
|
|
||||||
|
VERIFY( (is_same<add_reference<int>::type, int&>::value) );
|
||||||
|
VERIFY( (is_same<add_reference<int&>::type, int&>::value) );
|
||||||
|
VERIFY( (is_same<add_reference<const int>::type, const int&>::value) );
|
||||||
|
VERIFY( (is_same<add_reference<int*>::type, int*&>::value) );
|
||||||
|
VERIFY( (is_same<add_reference<ClassType&>::type, ClassType&>::value) );
|
||||||
|
VERIFY( (is_same<add_reference<ClassType>::type, ClassType&>::value) );
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
// 2004-12-08 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
//
|
||||||
|
// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free
|
||||||
|
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||||
|
// USA.
|
||||||
|
|
||||||
|
// 4.7.2 Reference modifications
|
||||||
|
|
||||||
|
#include <tr1/type_traits>
|
||||||
|
#include <testsuite_hooks.h>
|
||||||
|
#include <testsuite_tr1.h>
|
||||||
|
|
||||||
|
void test01()
|
||||||
|
{
|
||||||
|
bool test __attribute__((unused)) = true;
|
||||||
|
using std::tr1::remove_reference;
|
||||||
|
using std::tr1::is_same;
|
||||||
|
using namespace __gnu_test;
|
||||||
|
|
||||||
|
VERIFY( (is_same<remove_reference<int&>::type, int>::value) );
|
||||||
|
VERIFY( (is_same<remove_reference<int>::type, int>::value) );
|
||||||
|
VERIFY( (is_same<remove_reference<const int&>::type, const int>::value) );
|
||||||
|
VERIFY( (is_same<remove_reference<int*&>::type, int*>::value) );
|
||||||
|
VERIFY( (is_same<remove_reference<ClassType&>::type, ClassType>::value) );
|
||||||
|
VERIFY( (is_same<remove_reference<ClassType>::type, ClassType>::value) );
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
// 2004-12-08 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
//
|
||||||
|
// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free
|
||||||
|
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||||
|
// USA.
|
||||||
|
|
||||||
|
// 4.6 Relationships between types
|
||||||
|
|
||||||
|
#include <tr1/type_traits>
|
||||||
|
#include <testsuite_hooks.h>
|
||||||
|
#include <testsuite_tr1.h>
|
||||||
|
|
||||||
|
void test01()
|
||||||
|
{
|
||||||
|
bool test __attribute__((unused)) = true;
|
||||||
|
using std::tr1::is_same;
|
||||||
|
using namespace __gnu_test;
|
||||||
|
|
||||||
|
// Positive tests.
|
||||||
|
VERIFY( (test_relationship<is_same, int, int, true>()) );
|
||||||
|
VERIFY( (test_relationship<is_same, const int, const int, true>()) );
|
||||||
|
VERIFY( (test_relationship<is_same, int&, int&, true>()) );
|
||||||
|
VERIFY( (test_relationship<is_same, ClassType, ClassType, true>()) );
|
||||||
|
|
||||||
|
// Negative tests.
|
||||||
|
VERIFY( (test_relationship<is_same, void, int, false>()) );
|
||||||
|
VERIFY( (test_relationship<is_same, int, const int, false>()) );
|
||||||
|
VERIFY( (test_relationship<is_same, int, int&, false>()) );
|
||||||
|
VERIFY( (test_relationship<is_same, int, ClassType, false>()) );
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
// 2004-12-08 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
//
|
||||||
|
// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free
|
||||||
|
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||||
|
// USA.
|
||||||
|
|
||||||
|
//
|
||||||
|
// NB: This file is for testing tr1/type_traits with NO OTHER INCLUDES.
|
||||||
|
|
||||||
|
#include <tr1/type_traits>
|
||||||
|
|
||||||
|
// { dg-do compile }
|
||||||
|
|
||||||
|
void test01()
|
||||||
|
{
|
||||||
|
// Check for required typedefs
|
||||||
|
typedef std::tr1::is_same<int, int> test_type;
|
||||||
|
typedef test_type::value_type value_type;
|
||||||
|
typedef test_type::type type;
|
||||||
|
typedef test_type::type::value_type type_value_type;
|
||||||
|
typedef test_type::type::type type_type;
|
||||||
|
}
|
||||||
|
|
@ -31,14 +31,14 @@ void test01()
|
||||||
using namespace __gnu_test;
|
using namespace __gnu_test;
|
||||||
|
|
||||||
// Positive tests.
|
// Positive tests.
|
||||||
VERIFY( (test_property<is_const, int const, true>()) );
|
VERIFY( (test_property<is_const, const int, true>()) );
|
||||||
VERIFY( (test_property<is_const, int const volatile, true>()) );
|
VERIFY( (test_property<is_const, const volatile int, true>()) );
|
||||||
VERIFY( (test_property<is_const, cClassType, true>()) );
|
VERIFY( (test_property<is_const, cClassType, true>()) );
|
||||||
VERIFY( (test_property<is_const, cvClassType, true>()) );
|
VERIFY( (test_property<is_const, cvClassType, true>()) );
|
||||||
|
|
||||||
// Negative tests.
|
// Negative tests.
|
||||||
VERIFY( (test_property<is_const, int, false>()) );
|
VERIFY( (test_property<is_const, int, false>()) );
|
||||||
VERIFY( (test_property<is_const, int volatile, false>()) );
|
VERIFY( (test_property<is_const, volatile int, false>()) );
|
||||||
VERIFY( (test_property<is_const, ClassType, false>()) );
|
VERIFY( (test_property<is_const, ClassType, false>()) );
|
||||||
VERIFY( (test_property<is_const, vClassType, false>()) );
|
VERIFY( (test_property<is_const, vClassType, false>()) );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,14 +31,14 @@ void test01()
|
||||||
using namespace __gnu_test;
|
using namespace __gnu_test;
|
||||||
|
|
||||||
// Positive tests.
|
// Positive tests.
|
||||||
VERIFY( (test_property<is_volatile, int volatile, true>()) );
|
VERIFY( (test_property<is_volatile, volatile int, true>()) );
|
||||||
VERIFY( (test_property<is_volatile, int const volatile, true>()) );
|
VERIFY( (test_property<is_volatile, const volatile int, true>()) );
|
||||||
VERIFY( (test_property<is_volatile, vClassType, true>()) );
|
VERIFY( (test_property<is_volatile, vClassType, true>()) );
|
||||||
VERIFY( (test_property<is_volatile, cvClassType, true>()) );
|
VERIFY( (test_property<is_volatile, cvClassType, true>()) );
|
||||||
|
|
||||||
// Negative tests.
|
// Negative tests.
|
||||||
VERIFY( (test_property<is_volatile, int, false>()) );
|
VERIFY( (test_property<is_volatile, int, false>()) );
|
||||||
VERIFY( (test_property<is_volatile, int const, false>()) );
|
VERIFY( (test_property<is_volatile, const int, false>()) );
|
||||||
VERIFY( (test_property<is_volatile, ClassType, false>()) );
|
VERIFY( (test_property<is_volatile, ClassType, false>()) );
|
||||||
VERIFY( (test_property<is_volatile, cClassType, false>()) );
|
VERIFY( (test_property<is_volatile, cClassType, false>()) );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue