mirror of git://gcc.gnu.org/git/gcc.git
type_traits: Implement is_function.
2004-12-16 Paolo Carlini <pcarlini@suse.de> * include/tr1/type_traits: Implement is_function. (struct __sfinae_types, struct __is_function_helper): New. * testsuite/tr1/4_metaprogramming/composite_type_traits/ is_object/is_object.cc: New. * testsuite/tr1/4_metaprogramming/composite_type_traits/ is_object/typedefs.cc: Likewise. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_function/is_function.cc: Likewise. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_function/typedefs.cc: Likewise. From-SVN: r92258
This commit is contained in:
parent
8a784e4a17
commit
cacd0a2ccf
|
|
@ -1,3 +1,16 @@
|
||||||
|
2004-12-16 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
|
||||||
|
* include/tr1/type_traits: Implement is_function.
|
||||||
|
(struct __sfinae_types, struct __is_function_helper): New.
|
||||||
|
* testsuite/tr1/4_metaprogramming/composite_type_traits/
|
||||||
|
is_object/is_object.cc: New.
|
||||||
|
* testsuite/tr1/4_metaprogramming/composite_type_traits/
|
||||||
|
is_object/typedefs.cc: Likewise.
|
||||||
|
* testsuite/tr1/4_metaprogramming/primary_type_categories/
|
||||||
|
is_function/is_function.cc: Likewise.
|
||||||
|
* testsuite/tr1/4_metaprogramming/primary_type_categories/
|
||||||
|
is_function/typedefs.cc: Likewise.
|
||||||
|
|
||||||
2004-12-13 Paolo Carlini <pcarlini@suse.de>
|
2004-12-13 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
|
||||||
* include/tr1/type_traits (extent): Minor tweak (i.e., public).
|
* include/tr1/type_traits (extent): Minor tweak (i.e., public).
|
||||||
|
|
|
||||||
|
|
@ -28,21 +28,17 @@
|
||||||
#include <bits/c++config.h>
|
#include <bits/c++config.h>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
//namespace std::tr1
|
// namespace std::tr1
|
||||||
namespace std
|
namespace std
|
||||||
{
|
{
|
||||||
namespace tr1
|
namespace tr1
|
||||||
{
|
{
|
||||||
/// @brief helper classes [4.3].
|
// For use in is_function and elsewhere.
|
||||||
template<typename _Tp, _Tp __v>
|
struct __sfinae_types
|
||||||
struct integral_constant
|
{
|
||||||
{
|
typedef char __one;
|
||||||
static const _Tp value = __v;
|
typedef struct { char __arr[2]; } __two;
|
||||||
typedef _Tp value_type;
|
};
|
||||||
typedef integral_constant<_Tp, __v> type;
|
|
||||||
};
|
|
||||||
typedef integral_constant<bool, true> true_type;
|
|
||||||
typedef integral_constant<bool, false> false_type;
|
|
||||||
|
|
||||||
#define _DEFINE_SPEC_HELPER(_Header, _Spec) \
|
#define _DEFINE_SPEC_HELPER(_Header, _Spec) \
|
||||||
template _Header \
|
template _Header \
|
||||||
|
|
@ -55,6 +51,17 @@ namespace tr1
|
||||||
_DEFINE_SPEC_HELPER(_Header, _Trait<_Type volatile>) \
|
_DEFINE_SPEC_HELPER(_Header, _Trait<_Type volatile>) \
|
||||||
_DEFINE_SPEC_HELPER(_Header, _Trait<_Type const volatile>)
|
_DEFINE_SPEC_HELPER(_Header, _Trait<_Type const volatile>)
|
||||||
|
|
||||||
|
/// @brief helper classes [4.3].
|
||||||
|
template<typename _Tp, _Tp __v>
|
||||||
|
struct integral_constant
|
||||||
|
{
|
||||||
|
static const _Tp value = __v;
|
||||||
|
typedef _Tp value_type;
|
||||||
|
typedef integral_constant<_Tp, __v> type;
|
||||||
|
};
|
||||||
|
typedef integral_constant<bool, true> true_type;
|
||||||
|
typedef integral_constant<bool, false> false_type;
|
||||||
|
|
||||||
/// @brief primary type categories [4.5.1].
|
/// @brief primary type categories [4.5.1].
|
||||||
template<typename>
|
template<typename>
|
||||||
struct is_void
|
struct is_void
|
||||||
|
|
@ -126,9 +133,30 @@ namespace tr1
|
||||||
|
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
struct is_class;
|
struct is_class;
|
||||||
|
|
||||||
|
template<typename _Tp>
|
||||||
|
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>
|
template<typename _Tp>
|
||||||
struct is_function;
|
struct is_function
|
||||||
|
: public integral_constant<bool, (__is_function_helper<_Tp>::__value
|
||||||
|
&& !is_reference<_Tp>::value
|
||||||
|
&& !is_void<_Tp>::value)>
|
||||||
|
{ };
|
||||||
|
|
||||||
/// @brief composite type traits [4.5.2].
|
/// @brief composite type traits [4.5.2].
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
// 2004-12-16 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.2 Composite type traits
|
||||||
|
|
||||||
|
#include <tr1/type_traits>
|
||||||
|
#include <testsuite_hooks.h>
|
||||||
|
#include <testsuite_tr1.h>
|
||||||
|
|
||||||
|
void test01()
|
||||||
|
{
|
||||||
|
bool test __attribute__((unused)) = true;
|
||||||
|
using std::tr1::is_object;
|
||||||
|
using namespace __gnu_test;
|
||||||
|
|
||||||
|
VERIFY( (test_category<is_object, int (int)>(false)) );
|
||||||
|
VERIFY( (test_category<is_object, ClassType (ClassType)>(false)) );
|
||||||
|
VERIFY( (test_category<is_object, float (int, float, int[], int&)>(false)) );
|
||||||
|
VERIFY( (test_category<is_object, int&>(false)) );
|
||||||
|
VERIFY( (test_category<is_object, ClassType&>(false)) );
|
||||||
|
VERIFY( (test_category<is_object, int(&)(int)>(false)) );
|
||||||
|
VERIFY( (test_category<is_object, void>(false)) );
|
||||||
|
VERIFY( (test_category<is_object, const void>(false)) );
|
||||||
|
|
||||||
|
// Sanity check.
|
||||||
|
VERIFY( (test_category<is_object, ClassType>(true)) );
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
// 2004-12-16 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_object<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,51 @@
|
||||||
|
// 2004-12-16 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.1 Primary type categories
|
||||||
|
|
||||||
|
#include <tr1/type_traits>
|
||||||
|
#include <testsuite_hooks.h>
|
||||||
|
#include <testsuite_tr1.h>
|
||||||
|
|
||||||
|
void test01()
|
||||||
|
{
|
||||||
|
bool test __attribute__((unused)) = true;
|
||||||
|
using std::tr1::is_function;
|
||||||
|
using namespace __gnu_test;
|
||||||
|
|
||||||
|
// Positive tests.
|
||||||
|
VERIFY( (test_category<is_function, int (int)>(true)) );
|
||||||
|
VERIFY( (test_category<is_function, ClassType (ClassType)>(true)) );
|
||||||
|
VERIFY( (test_category<is_function, float (int, float, int[], int&)>(true)) );
|
||||||
|
|
||||||
|
// Negative tests.
|
||||||
|
VERIFY( (test_category<is_function, int&>(false)) );
|
||||||
|
VERIFY( (test_category<is_function, void>(false)) );
|
||||||
|
VERIFY( (test_category<is_function, const void>(false)) );
|
||||||
|
|
||||||
|
// Sanity check.
|
||||||
|
VERIFY( (test_category<is_function, ClassType>(false)) );
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
// 2004-12-16 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_function<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…
Reference in New Issue