diff options
author | Paolo Carlini <pcarlini@suse.de> | 2005-01-24 14:06:13 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2005-01-24 14:06:13 +0000 |
commit | e930780c1eb7656f60a9e3d42ad5f91432fad363 (patch) | |
tree | e3562576248e2b27e95999f4d251a631c24a630e | |
parent | 226c62c799e992c841f0cc0ea11b336dfa1dad06 (diff) | |
download | gcc-e930780c1eb7656f60a9e3d42ad5f91432fad363.zip gcc-e930780c1eb7656f60a9e3d42ad5f91432fad363.tar.gz gcc-e930780c1eb7656f60a9e3d42ad5f91432fad363.tar.bz2 |
type_traits: Implement is_signed and is_unsigned.
2005-01-24 Paolo Carlini <pcarlini@suse.de>
* include/tr1/type_traits: Implement is_signed and is_unsigned.
* testsuite/tr1/4_metaprogramming/type_properties/
is_signed/is_signed.cc: New.
* testsuite/tr1/4_metaprogramming/type_properties/
is_signed/typedefs.cc: Likewise.
* testsuite/tr1/4_metaprogramming/type_properties/
is_unsigned/is_unsigned.cc: Likewise.
* testsuite/tr1/4_metaprogramming/type_properties/
is_unsigned/typedefs.cc: Likewise.
From-SVN: r94160
6 files changed, 226 insertions, 0 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 3ef5e29..8b95181 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,15 @@ +2005-01-24 Paolo Carlini <pcarlini@suse.de> + + * include/tr1/type_traits: Implement is_signed and is_unsigned. + * testsuite/tr1/4_metaprogramming/type_properties/ + is_signed/is_signed.cc: New. + * testsuite/tr1/4_metaprogramming/type_properties/ + is_signed/typedefs.cc: Likewise. + * testsuite/tr1/4_metaprogramming/type_properties/ + is_unsigned/is_unsigned.cc: Likewise. + * testsuite/tr1/4_metaprogramming/type_properties/ + is_unsigned/typedefs.cc: Likewise. + 2005-01-23 Paolo Carlini <pcarlini@suse.de> * docs/html/ext/lwg-active.html, lwg-defects.html: Import Revision 34. diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits index 7fca1b8..34c1c9f 100644 --- a/libstdc++-v3/include/tr1/type_traits +++ b/libstdc++-v3/include/tr1/type_traits @@ -517,6 +517,24 @@ namespace tr1 struct has_virtual_destructor : public false_type { }; + template<typename> + struct is_signed + : public false_type { }; + _DEFINE_SPEC(0, is_signed, signed char, true) + _DEFINE_SPEC(0, is_signed, short, true) + _DEFINE_SPEC(0, is_signed, int, true) + _DEFINE_SPEC(0, is_signed, long, true) + _DEFINE_SPEC(0, is_signed, long long, true) + + template<typename> + struct is_unsigned + : public false_type { }; + _DEFINE_SPEC(0, is_unsigned, unsigned char, true) + _DEFINE_SPEC(0, is_unsigned, unsigned short, true) + _DEFINE_SPEC(0, is_unsigned, unsigned int, true) + _DEFINE_SPEC(0, is_unsigned, unsigned long, true) + _DEFINE_SPEC(0, is_unsigned, unsigned long long, true) + template<typename _Tp> struct alignment_of : public integral_constant<std::size_t, __alignof__(_Tp)> { }; diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_signed/is_signed.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_signed/is_signed.cc new file mode 100644 index 0000000..a987df2 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_signed/is_signed.cc @@ -0,0 +1,62 @@ +// 2005-01-24 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2005 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_signed; + using namespace __gnu_test; + + VERIFY( (test_category<is_signed, void>(false)) ); + + VERIFY( (test_category<is_signed, char>(false)) ); + VERIFY( (test_category<is_signed, signed char>(true)) ); + VERIFY( (test_category<is_signed, unsigned char>(false)) ); +#ifdef _GLIBCXX_USE_WCHAR_T + VERIFY( (test_category<is_signed, wchar_t>(false)) ); +#endif + VERIFY( (test_category<is_signed, short>(true)) ); + VERIFY( (test_category<is_signed, unsigned short>(false)) ); + VERIFY( (test_category<is_signed, int>(true)) ); + VERIFY( (test_category<is_signed, unsigned int>(false)) ); + VERIFY( (test_category<is_signed, long>(true)) ); + VERIFY( (test_category<is_signed, unsigned long>(false)) ); + VERIFY( (test_category<is_signed, long long>(true)) ); + VERIFY( (test_category<is_signed, unsigned long long>(false)) ); + + VERIFY( (test_category<is_signed, float>(false)) ); + VERIFY( (test_category<is_signed, double>(false)) ); + VERIFY( (test_category<is_signed, long double>(false)) ); + + // Sanity check. + VERIFY( (test_category<is_signed, ClassType>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_signed/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_signed/typedefs.cc new file mode 100644 index 0000000..52a528a --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_signed/typedefs.cc @@ -0,0 +1,36 @@ +// 2005-01-24 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2005 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_signed<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; +} diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_unsigned/is_unsigned.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_unsigned/is_unsigned.cc new file mode 100644 index 0000000..fc444b5 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_unsigned/is_unsigned.cc @@ -0,0 +1,62 @@ +// 2005-01-24 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2005 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_unsigned; + using namespace __gnu_test; + + VERIFY( (test_category<is_unsigned, void>(false)) ); + + VERIFY( (test_category<is_unsigned, char>(false)) ); + VERIFY( (test_category<is_unsigned, signed char>(false)) ); + VERIFY( (test_category<is_unsigned, unsigned char>(true)) ); +#ifdef _GLIBCXX_USE_WCHAR_T + VERIFY( (test_category<is_unsigned, wchar_t>(false)) ); +#endif + VERIFY( (test_category<is_unsigned, short>(false)) ); + VERIFY( (test_category<is_unsigned, unsigned short>(true)) ); + VERIFY( (test_category<is_unsigned, int>(false)) ); + VERIFY( (test_category<is_unsigned, unsigned int>(true)) ); + VERIFY( (test_category<is_unsigned, long>(false)) ); + VERIFY( (test_category<is_unsigned, unsigned long>(true)) ); + VERIFY( (test_category<is_unsigned, long long>(false)) ); + VERIFY( (test_category<is_unsigned, unsigned long long>(true)) ); + + VERIFY( (test_category<is_unsigned, float>(false)) ); + VERIFY( (test_category<is_unsigned, double>(false)) ); + VERIFY( (test_category<is_unsigned, long double>(false)) ); + + // Sanity check. + VERIFY( (test_category<is_unsigned, ClassType>(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_unsigned/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_unsigned/typedefs.cc new file mode 100644 index 0000000..195a80c --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_unsigned/typedefs.cc @@ -0,0 +1,36 @@ +// 2005-01-24 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2005 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_unsigned<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; +} |