type_traits: Implement is_const and is_volatile.
2004-12-07 Paolo Carlini <pcarlini@suse.de> * include/tr1/type_traits: Implement is_const and is_volatile. * testsuite/testsuite_tr1.h (test_property): New. * testsuite/tr1/4_metaprogramming/type_properties/ is_const/is_const.c: New. * testsuite/tr1/4_metaprogramming/type_properties/ is_const/typedefs.cc: Likewise. * testsuite/tr1/4_metaprogramming/type_properties/ is_volatile/is_volatile.cc: Likewise. * testsuite/tr1/4_metaprogramming/type_properties/ is_volatile/typedefs.cc: Likewise. * testsuite/tr1/4_metaprogramming/composite_type_traits/ is_arithmetic/is_arithmetic.cc: Slightly tweak to use ClassType from testsuite_tr1.h. * testsuite/tr1/4_metaprogramming/composite_type_traits/ is_fundamental/is_fundamental.cc: Likewise. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_array/is_array.cc: Likewise. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_floating_point/is_floating_point.cc: Likewise. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_integral/is_integral.cc: Likewise. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_reference/is_reference.cc: Likewise. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_void/is_void.cc: Likewise. From-SVN: r91808
This commit is contained in:
parent
5423d7ebe1
commit
0f910b4f4f
14 changed files with 236 additions and 23 deletions
|
@ -1,3 +1,31 @@
|
|||
2004-12-07 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
* include/tr1/type_traits: Implement is_const and is_volatile.
|
||||
* testsuite/testsuite_tr1.h (test_property): New.
|
||||
* testsuite/tr1/4_metaprogramming/type_properties/
|
||||
is_const/is_const.c: New.
|
||||
* testsuite/tr1/4_metaprogramming/type_properties/
|
||||
is_const/typedefs.cc: Likewise.
|
||||
* testsuite/tr1/4_metaprogramming/type_properties/
|
||||
is_volatile/is_volatile.cc: Likewise.
|
||||
* testsuite/tr1/4_metaprogramming/type_properties/
|
||||
is_volatile/typedefs.cc: Likewise.
|
||||
* testsuite/tr1/4_metaprogramming/composite_type_traits/
|
||||
is_arithmetic/is_arithmetic.cc: Slightly tweak to use ClassType
|
||||
from testsuite_tr1.h.
|
||||
* testsuite/tr1/4_metaprogramming/composite_type_traits/
|
||||
is_fundamental/is_fundamental.cc: Likewise.
|
||||
* testsuite/tr1/4_metaprogramming/primary_type_categories/
|
||||
is_array/is_array.cc: Likewise.
|
||||
* testsuite/tr1/4_metaprogramming/primary_type_categories/
|
||||
is_floating_point/is_floating_point.cc: Likewise.
|
||||
* testsuite/tr1/4_metaprogramming/primary_type_categories/
|
||||
is_integral/is_integral.cc: Likewise.
|
||||
* testsuite/tr1/4_metaprogramming/primary_type_categories/
|
||||
is_reference/is_reference.cc: Likewise.
|
||||
* testsuite/tr1/4_metaprogramming/primary_type_categories/
|
||||
is_void/is_void.cc: Likewise.
|
||||
|
||||
2004-12-06 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
* include/tr1/type_traits: Implement is_reference.
|
||||
|
|
|
@ -171,11 +171,21 @@ namespace tr1
|
|||
: public integral_constant<bool, !is_fundamental<_Tp>::value> { };
|
||||
|
||||
/// @brief type properties [4.5.3].
|
||||
template<typename>
|
||||
struct is_const
|
||||
: public false_type { };
|
||||
|
||||
template<typename _Tp>
|
||||
struct is_const;
|
||||
struct is_const<_Tp const>
|
||||
: public true_type { };
|
||||
|
||||
template<typename>
|
||||
struct is_volatile
|
||||
: public false_type { };
|
||||
|
||||
template<typename _Tp>
|
||||
struct is_volatile;
|
||||
struct is_volatile<_Tp volatile>
|
||||
: public true_type { };
|
||||
|
||||
template<typename _Tp>
|
||||
struct is_pod;
|
||||
|
|
|
@ -50,6 +50,23 @@ namespace __gnu_test
|
|||
ret &= Category<Type const volatile>::type::value == Tv;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<template<typename> class Property,
|
||||
typename Type, bool Tv>
|
||||
bool
|
||||
test_property()
|
||||
{
|
||||
bool ret = true;
|
||||
ret &= Property<Type>::value == Tv;
|
||||
ret &= Property<Type>::type::value == Tv;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Test types.
|
||||
class ClassType { };
|
||||
typedef ClassType const cClassType;
|
||||
typedef ClassType volatile vClassType;
|
||||
typedef ClassType const volatile cvClassType;
|
||||
}; // namespace __gnu_test
|
||||
|
||||
#endif // _GLIBCXX_TESTSUITE_TR1_H
|
||||
|
|
|
@ -24,13 +24,11 @@
|
|||
#include <testsuite_hooks.h>
|
||||
#include <testsuite_tr1.h>
|
||||
|
||||
class ClassType { };
|
||||
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
using std::tr1::is_arithmetic;
|
||||
using __gnu_test::test_category;
|
||||
using namespace __gnu_test;
|
||||
|
||||
VERIFY( (test_category<is_arithmetic, void, false>()) );
|
||||
|
||||
|
|
|
@ -24,13 +24,11 @@
|
|||
#include <testsuite_hooks.h>
|
||||
#include <testsuite_tr1.h>
|
||||
|
||||
class ClassType { };
|
||||
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
using std::tr1::is_fundamental;
|
||||
using __gnu_test::test_category;
|
||||
using namespace __gnu_test;
|
||||
|
||||
VERIFY( (test_category<is_fundamental, void, true>()) );
|
||||
VERIFY( (test_category<is_fundamental, char, true>()) );
|
||||
|
|
|
@ -24,13 +24,11 @@
|
|||
#include <testsuite_hooks.h>
|
||||
#include <testsuite_tr1.h>
|
||||
|
||||
class ClassType { };
|
||||
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
using std::tr1::is_array;
|
||||
using __gnu_test::test_category;
|
||||
using namespace __gnu_test;
|
||||
|
||||
typedef int int_array[5];
|
||||
typedef int empty_int_array[];
|
||||
|
|
|
@ -24,13 +24,11 @@
|
|||
#include <testsuite_hooks.h>
|
||||
#include <testsuite_tr1.h>
|
||||
|
||||
class ClassType { };
|
||||
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
using std::tr1::is_floating_point;
|
||||
using __gnu_test::test_category;
|
||||
using namespace __gnu_test;
|
||||
|
||||
VERIFY( (test_category<is_floating_point, void, false>()) );
|
||||
VERIFY( (test_category<is_floating_point, char, false>()) );
|
||||
|
|
|
@ -24,13 +24,11 @@
|
|||
#include <testsuite_hooks.h>
|
||||
#include <testsuite_tr1.h>
|
||||
|
||||
class ClassType { };
|
||||
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
using std::tr1::is_integral;
|
||||
using __gnu_test::test_category;
|
||||
using namespace __gnu_test;
|
||||
|
||||
VERIFY( (test_category<is_integral, void, false>()) );
|
||||
|
||||
|
|
|
@ -24,13 +24,11 @@
|
|||
#include <testsuite_hooks.h>
|
||||
#include <testsuite_tr1.h>
|
||||
|
||||
class ClassType { };
|
||||
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
using std::tr1::is_reference;
|
||||
using __gnu_test::test_category;
|
||||
using namespace __gnu_test;
|
||||
|
||||
typedef int& int_ref;
|
||||
typedef ClassType& ClassType_ref;
|
||||
|
|
|
@ -24,13 +24,11 @@
|
|||
#include <testsuite_hooks.h>
|
||||
#include <testsuite_tr1.h>
|
||||
|
||||
class ClassType { };
|
||||
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
using std::tr1::is_void;
|
||||
using __gnu_test::test_category;
|
||||
using namespace __gnu_test;
|
||||
|
||||
VERIFY( (test_category<is_void, void, true>()) );
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
// 2004-12-07 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.5.3 Type properties
|
||||
|
||||
#include <tr1/type_traits>
|
||||
#include <testsuite_hooks.h>
|
||||
#include <testsuite_tr1.h>
|
||||
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
using std::tr1::is_const;
|
||||
using namespace __gnu_test;
|
||||
|
||||
// Positive tests.
|
||||
VERIFY( (test_property<is_const, int const, true>()) );
|
||||
VERIFY( (test_property<is_const, int const volatile, true>()) );
|
||||
VERIFY( (test_property<is_const, cClassType, true>()) );
|
||||
VERIFY( (test_property<is_const, cvClassType, true>()) );
|
||||
|
||||
// Negative tests.
|
||||
VERIFY( (test_property<is_const, int, false>()) );
|
||||
VERIFY( (test_property<is_const, int volatile, false>()) );
|
||||
VERIFY( (test_property<is_const, ClassType, false>()) );
|
||||
VERIFY( (test_property<is_const, vClassType, false>()) );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
// 2004-12-07 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_const<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;
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
// 2004-12-07 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.5.3 Type properties
|
||||
|
||||
#include <tr1/type_traits>
|
||||
#include <testsuite_hooks.h>
|
||||
#include <testsuite_tr1.h>
|
||||
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
using std::tr1::is_volatile;
|
||||
using namespace __gnu_test;
|
||||
|
||||
// Positive tests.
|
||||
VERIFY( (test_property<is_volatile, int volatile, true>()) );
|
||||
VERIFY( (test_property<is_volatile, int const volatile, true>()) );
|
||||
VERIFY( (test_property<is_volatile, vClassType, true>()) );
|
||||
VERIFY( (test_property<is_volatile, cvClassType, true>()) );
|
||||
|
||||
// Negative tests.
|
||||
VERIFY( (test_property<is_volatile, int, false>()) );
|
||||
VERIFY( (test_property<is_volatile, int const, false>()) );
|
||||
VERIFY( (test_property<is_volatile, ClassType, false>()) );
|
||||
VERIFY( (test_property<is_volatile, cClassType, false>()) );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
// 2004-12-07 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_volatile<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;
|
||||
}
|
Loading…
Add table
Reference in a new issue