+2005-01-28 Paolo Carlini <pcarlini@suse.de>
+
+ * include/tr1/type_traits: Implement is_abstract, by exploiting the
+ resolution of DR core/337.
+ * testsuite/testsuite_tr1.h: Add AbstractClass.
+ * testsuite/tr1/4_metaprogramming/type_properties/is_abstract/
+ is_abstract.cc: New.
+ * testsuite/tr1/4_metaprogramming/type_properties/is_abstract/
+ typedefs.cc: Likewise.
+
+ * include/tr1/type_traits (is_function): Rewrite, use the conversion
+ F& -> F* instead, thus avoiding problems with abstract classes.
+ * testsuite/tr1/4_metaprogramming/primary_type_categories/
+ is_function/is_function.cc: Add a test for tricky AbstractClass.
+
2005-01-26 Paolo Carlini <pcarlini@suse.de>
* include/ext/mt_allocator.h
{
namespace tr1
{
- // For use in is_enum, is_function, and elsewhere.
+ // For use in is_enum, is_abstract and elsewhere.
struct __sfinae_types
{
typedef char __one;
typedef struct { char __arr[2]; } __two;
};
+ template<typename _From, typename _To>
+ struct __conv_helper
+ : public __sfinae_types
+ {
+ private:
+ static __one __test(_To);
+ static __two __test(...);
+ static _From __makeFrom();
+
+ public:
+ static const bool __value = sizeof(__test(__makeFrom())) == 1;
+ };
+
#define _DEFINE_SPEC_BODY(_Value) \
: public integral_constant<bool, _Value> { };
struct is_enum
: public integral_constant<bool, __is_enum_helper<_Tp>::__value> { };
- template<typename _Tp, bool = (is_reference<_Tp>::value
- || is_void<_Tp>::value)>
- struct __is_function_helper
- : public __sfinae_types
- {
- private:
- template<typename>
- static __one __test(...);
- template<typename _Up>
- static __two __test(_Up(*)[1]);
-
- public:
- static const bool __value = sizeof(__test<_Tp>(0)) == 1;
- };
-
- template<typename _Tp>
- struct __is_function_helper<_Tp, true>
- { static const bool __value = false; };
-
template<typename _Tp>
struct is_function
- : public integral_constant<bool, __is_function_helper<_Tp>::__value> { };
+ : public integral_constant<bool,
+ (__conv_helper<typename add_reference<_Tp>::type,
+ typename add_pointer<_Tp>::type>::__value)>
+ { };
+ _DEFINE_SPEC(0, is_function, void, false)
/// @brief composite type traits [4.5.2].
template<typename _Tp>
remove_all_extents<_Tp>::type>::value)>
{ };
+ // Exploit the resolution DR core/337.
+ template<typename _Tp, bool = (is_void<_Tp>::value
+ || is_function<_Tp>::value
+ || is_reference<_Tp>::value)>
+ struct __is_abstract_helper
+ : public __sfinae_types
+ {
+ private:
+ template<typename>
+ static __one __test(...);
+ template<typename _Up>
+ static __two __test(_Up(*)[1]);
+
+ public:
+ static const bool __value = sizeof(__test<_Tp>(0)) == 1;
+ };
+
+ template<typename _Tp>
+ struct __is_abstract_helper<_Tp, true>
+ { static const bool __value = false; };
+
+ template<typename _Tp>
+ struct is_abstract
+ : public integral_constant<bool, __is_abstract_helper<_Tp>::__value> { };
+
template<typename _Tp>
struct has_trivial_constructor
: public integral_constant<bool, is_pod<_Tp>::value> { };
// -*- C++ -*-
// Testing utilities for the tr1 testsuite.
//
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 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
struct ConvType
{ operator int() const; };
+
+ class AbstractClass
+ { virtual void rotate(int) = 0; };
}; // namespace __gnu_test
// 2004-12-16 Paolo Carlini <pcarlini@suse.de>
//
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 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
VERIFY( (test_category<is_function, int&>(false)) );
VERIFY( (test_category<is_function, void>(false)) );
VERIFY( (test_category<is_function, const void>(false)) );
+
+ VERIFY( (test_category<is_function, AbstractClass>(false)) );
// Sanity check.
VERIFY( (test_category<is_function, ClassType>(false)) );
--- /dev/null
+// 2005-01-28 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_abstract;
+ using namespace __gnu_test;
+
+ // Positive tests.
+ VERIFY( (test_category<is_abstract, AbstractClass>(true)) );
+
+ // Negative tests.
+ VERIFY( (test_category<is_abstract, void>(false)) );
+ VERIFY( (test_category<is_abstract, int (int)>(false)) );
+ VERIFY( (test_category<is_abstract, int&>(false)) );
+
+ // Sanity check.
+ VERIFY( (test_category<is_abstract, ClassType>(false)) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// 2005-01-28 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_abstract<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;
+}