From: Paolo Carlini Date: Wed, 23 Feb 2005 17:23:44 +0000 (+0000) Subject: type_traits: Implement is_convertible. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c150a271b1fa7ad02b245dea1579b3f2e981e85a;p=gcc.git type_traits: Implement is_convertible. 2005-02-23 Paolo Carlini * include/tr1/type_traits: Implement is_convertible. * testsuite/tr1/4_metaprogramming/relationships_between_types/ is_convertible/is_convertible.cc: New. * testsuite/tr1/4_metaprogramming/relationships_between_types/ is_convertible/typedefs.cc: Likewise. * testsuite/testsuite_tr1.h: Add class DerivedType. * include/tr1/type_traits (is_function): Don't mistake references to function types for function types. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_function/is_function.cc: Add testcase. From-SVN: r95458 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index bd1091c5819..14e038d4fa4 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,17 @@ +2005-02-23 Paolo Carlini + + * include/tr1/type_traits: Implement is_convertible. + * testsuite/tr1/4_metaprogramming/relationships_between_types/ + is_convertible/is_convertible.cc: New. + * testsuite/tr1/4_metaprogramming/relationships_between_types/ + is_convertible/typedefs.cc: Likewise. + * testsuite/testsuite_tr1.h: Add class DerivedType. + + * include/tr1/type_traits (is_function): Don't mistake references + to function types for function types. + * testsuite/tr1/4_metaprogramming/primary_type_categories/ + is_function/is_function.cc: Add testcase. + 2005-02-22 Benjamin Kosnik * scripts/check_performance: Tweaks. diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits index c4c1ff487f0..0fb5916fc65 100644 --- a/libstdc++-v3/include/tr1/type_traits +++ b/libstdc++-v3/include/tr1/type_traits @@ -208,7 +208,8 @@ namespace tr1 struct is_enum : public integral_constant::__value> { }; - template::value> + template::value + || is_reference<_Tp>::value)> struct __is_function_helper { static const bool __value = (__conv_helper : public true_type { }; + template + struct __is_int_or_cref + { + typedef typename remove_reference<_Tp>::type __rr_Tp; + static const bool __value = (is_integral<_Tp>::value + || (is_integral<__rr_Tp>::value + && is_const<__rr_Tp>::value + && !is_volatile<__rr_Tp>::value)); + }; + + template::value || is_array<_To>::value + // This special case is here only to avoid warnings. + || (is_floating_point::type>::value + && __is_int_or_cref<_To>::__value))> + struct __is_convertible_helper + { + // "An imaginary lvalue of type From...". + static const bool __value = (__conv_helper::type, _To>::__value); + }; + + template + struct __is_convertible_helper<_From, _To, true> + { static const bool __value = __is_int_or_cref<_To>::__value; }; + + template + struct is_convertible + : public integral_constant::__value> + { }; + /// @brief const-volatile modifications [4.7.1]. template struct remove_const diff --git a/libstdc++-v3/testsuite/testsuite_tr1.h b/libstdc++-v3/testsuite/testsuite_tr1.h index 74a187666fd..a0302c13653 100644 --- a/libstdc++-v3/testsuite/testsuite_tr1.h +++ b/libstdc++-v3/testsuite/testsuite_tr1.h @@ -113,6 +113,8 @@ namespace __gnu_test typedef volatile ClassType vClassType; typedef const volatile ClassType cvClassType; + class DerivedType : public ClassType { }; + enum EnumType { }; struct ConvType diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/is_function.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/is_function.cc index 4bbda75280b..1c8d64dca4d 100644 --- a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/is_function.cc +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/is_function.cc @@ -41,6 +41,7 @@ void test01() VERIFY( (test_category(false)) ); VERIFY( (test_category(false)) ); + VERIFY( (test_category(false)) ); // Sanity check. VERIFY( (test_category(false)) ); diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_convertible/is_convertible.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_convertible/is_convertible.cc new file mode 100644 index 00000000000..858bfda3ad1 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_convertible/is_convertible.cc @@ -0,0 +1,79 @@ +// 2005-02-23 Paolo Carlini +// +// 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.6 Relationships between types + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using std::tr1::is_convertible; + using namespace __gnu_test; + + // Positive tests. + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + VERIFY( (test_relationship(true)) ); + + // Negative tests. + VERIFY( (test_relationship(false)) ); + VERIFY( (test_relationship(false)) ); + VERIFY( (test_relationship(false)) ); + VERIFY( (test_relationship(false)) ); + VERIFY( (test_relationship(false)) ); + VERIFY( (test_relationship(false)) ); + VERIFY( (test_relationship(false)) ); + VERIFY( (test_relationship(false)) ); + VERIFY( (test_relationship(false)) ); + VERIFY( (test_relationship(false)) ); + VERIFY( (test_relationship(false)) ); + VERIFY( (test_relationship(false)) ); + VERIFY( (test_relationship(false)) ); + VERIFY( (test_relationship(false)) ); + VERIFY( (test_relationship(false)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_convertible/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_convertible/typedefs.cc new file mode 100644 index 00000000000..333c405ac0c --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_convertible/typedefs.cc @@ -0,0 +1,36 @@ +// 2005-02-23 Paolo Carlini +// +// 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 + +// { dg-do compile } + +void test01() +{ + // Check for required typedefs + typedef std::tr1::is_convertible 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; +}