// TR1 type_traits -*- C++ -*-
|
// TR1 type_traits -*- C++ -*-
|
|
|
// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
|
// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
|
//
|
//
|
// This file is part of the GNU ISO C++ Library. This library is free
|
// 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
|
// software; you can redistribute it and/or modify it under the
|
// terms of the GNU General Public License as published by the
|
// terms of the GNU General Public License as published by the
|
// Free Software Foundation; either version 3, or (at your option)
|
// Free Software Foundation; either version 3, or (at your option)
|
// any later version.
|
// any later version.
|
|
|
// This library is distributed in the hope that it will be useful,
|
// This library is distributed in the hope that it will be useful,
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// GNU General Public License for more details.
|
// GNU General Public License for more details.
|
|
|
// Under Section 7 of GPL version 3, you are granted additional
|
// Under Section 7 of GPL version 3, you are granted additional
|
// permissions described in the GCC Runtime Library Exception, version
|
// permissions described in the GCC Runtime Library Exception, version
|
// 3.1, as published by the Free Software Foundation.
|
// 3.1, as published by the Free Software Foundation.
|
|
|
// You should have received a copy of the GNU General Public License and
|
// You should have received a copy of the GNU General Public License and
|
// a copy of the GCC Runtime Library Exception along with this program;
|
// a copy of the GCC Runtime Library Exception along with this program;
|
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
// .
|
// .
|
|
|
/** @file tr1/type_traits
|
/** @file tr1/type_traits
|
* This is a TR1 C++ Library header.
|
* This is a TR1 C++ Library header.
|
*/
|
*/
|
|
|
#ifndef _GLIBCXX_TR1_TYPE_TRAITS
|
#ifndef _GLIBCXX_TR1_TYPE_TRAITS
|
#define _GLIBCXX_TR1_TYPE_TRAITS 1
|
#define _GLIBCXX_TR1_TYPE_TRAITS 1
|
|
|
#pragma GCC system_header
|
#pragma GCC system_header
|
|
|
#if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
|
#if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
|
# error TR1 header cannot be included from C++0x header
|
# error TR1 header cannot be included from C++0x header
|
#endif
|
#endif
|
|
|
#include
|
#include
|
|
|
#if defined(_GLIBCXX_INCLUDE_AS_TR1)
|
#if defined(_GLIBCXX_INCLUDE_AS_TR1)
|
# include
|
# include
|
#else
|
#else
|
# define _GLIBCXX_INCLUDE_AS_TR1
|
# define _GLIBCXX_INCLUDE_AS_TR1
|
# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 {
|
# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 {
|
# define _GLIBCXX_END_NAMESPACE_TR1 }
|
# define _GLIBCXX_END_NAMESPACE_TR1 }
|
# define _GLIBCXX_TR1 tr1::
|
# define _GLIBCXX_TR1 tr1::
|
# include
|
# include
|
# undef _GLIBCXX_TR1
|
# undef _GLIBCXX_TR1
|
# undef _GLIBCXX_END_NAMESPACE_TR1
|
# undef _GLIBCXX_END_NAMESPACE_TR1
|
# undef _GLIBCXX_BEGIN_NAMESPACE_TR1
|
# undef _GLIBCXX_BEGIN_NAMESPACE_TR1
|
# undef _GLIBCXX_INCLUDE_AS_TR1
|
# undef _GLIBCXX_INCLUDE_AS_TR1
|
#endif
|
#endif
|
|
|
namespace std
|
namespace std
|
{
|
{
|
namespace tr1
|
namespace tr1
|
{
|
{
|
#define _DEFINE_SPEC(_Trait, _Type) \
|
#define _DEFINE_SPEC(_Trait, _Type) \
|
template<> \
|
template<> \
|
struct _Trait<_Type> \
|
struct _Trait<_Type> \
|
: public true_type { };
|
: public true_type { };
|
|
|
template
|
template
|
struct is_reference
|
struct is_reference
|
: public false_type { };
|
: public false_type { };
|
|
|
template
|
template
|
struct is_reference<_Tp&>
|
struct is_reference<_Tp&>
|
: public true_type { };
|
: public true_type { };
|
|
|
template
|
template
|
struct is_pod
|
struct is_pod
|
: public integral_constant::value>
|
: public integral_constant::value>
|
{ };
|
{ };
|
|
|
template
|
template
|
struct has_trivial_constructor
|
struct has_trivial_constructor
|
: public integral_constant::value>
|
: public integral_constant::value>
|
{ };
|
{ };
|
|
|
template
|
template
|
struct has_trivial_copy
|
struct has_trivial_copy
|
: public integral_constant::value>
|
: public integral_constant::value>
|
{ };
|
{ };
|
|
|
template
|
template
|
struct has_trivial_assign
|
struct has_trivial_assign
|
: public integral_constant::value>
|
: public integral_constant::value>
|
{ };
|
{ };
|
|
|
template
|
template
|
struct has_trivial_destructor
|
struct has_trivial_destructor
|
: public integral_constant::value>
|
: public integral_constant::value>
|
{ };
|
{ };
|
|
|
template
|
template
|
struct has_nothrow_constructor
|
struct has_nothrow_constructor
|
: public integral_constant::value>
|
: public integral_constant::value>
|
{ };
|
{ };
|
|
|
template
|
template
|
struct has_nothrow_copy
|
struct has_nothrow_copy
|
: public integral_constant::value>
|
: public integral_constant::value>
|
{ };
|
{ };
|
|
|
template
|
template
|
struct has_nothrow_assign
|
struct has_nothrow_assign
|
: public integral_constant::value>
|
: public integral_constant::value>
|
{ };
|
{ };
|
|
|
template
|
template
|
struct __is_signed_helper
|
struct __is_signed_helper
|
: public false_type { };
|
: public false_type { };
|
_DEFINE_SPEC(__is_signed_helper, signed char)
|
_DEFINE_SPEC(__is_signed_helper, signed char)
|
_DEFINE_SPEC(__is_signed_helper, short)
|
_DEFINE_SPEC(__is_signed_helper, short)
|
_DEFINE_SPEC(__is_signed_helper, int)
|
_DEFINE_SPEC(__is_signed_helper, int)
|
_DEFINE_SPEC(__is_signed_helper, long)
|
_DEFINE_SPEC(__is_signed_helper, long)
|
_DEFINE_SPEC(__is_signed_helper, long long)
|
_DEFINE_SPEC(__is_signed_helper, long long)
|
|
|
template
|
template
|
struct is_signed
|
struct is_signed
|
: public integral_constant
|
: public integral_constant
|
remove_cv<_Tp>::type>::value)>
|
remove_cv<_Tp>::type>::value)>
|
{ };
|
{ };
|
|
|
template
|
template
|
struct __is_unsigned_helper
|
struct __is_unsigned_helper
|
: public false_type { };
|
: public false_type { };
|
_DEFINE_SPEC(__is_unsigned_helper, unsigned char)
|
_DEFINE_SPEC(__is_unsigned_helper, unsigned char)
|
_DEFINE_SPEC(__is_unsigned_helper, unsigned short)
|
_DEFINE_SPEC(__is_unsigned_helper, unsigned short)
|
_DEFINE_SPEC(__is_unsigned_helper, unsigned int)
|
_DEFINE_SPEC(__is_unsigned_helper, unsigned int)
|
_DEFINE_SPEC(__is_unsigned_helper, unsigned long)
|
_DEFINE_SPEC(__is_unsigned_helper, unsigned long)
|
_DEFINE_SPEC(__is_unsigned_helper, unsigned long long)
|
_DEFINE_SPEC(__is_unsigned_helper, unsigned long long)
|
|
|
template
|
template
|
struct is_unsigned
|
struct is_unsigned
|
: public integral_constant
|
: public integral_constant
|
remove_cv<_Tp>::type>::value)>
|
remove_cv<_Tp>::type>::value)>
|
{ };
|
{ };
|
|
|
template
|
template
|
struct __is_base_of_helper
|
struct __is_base_of_helper
|
{
|
{
|
typedef typename remove_cv<_Base>::type _NoCv_Base;
|
typedef typename remove_cv<_Base>::type _NoCv_Base;
|
typedef typename remove_cv<_Derived>::type _NoCv_Derived;
|
typedef typename remove_cv<_Derived>::type _NoCv_Derived;
|
static const bool __value = (is_same<_Base, _Derived>::value
|
static const bool __value = (is_same<_Base, _Derived>::value
|
|| (__is_base_of(_Base, _Derived)
|
|| (__is_base_of(_Base, _Derived)
|
&& !is_same<_NoCv_Base,
|
&& !is_same<_NoCv_Base,
|
_NoCv_Derived>::value));
|
_NoCv_Derived>::value));
|
};
|
};
|
|
|
template
|
template
|
struct is_base_of
|
struct is_base_of
|
: public integral_constant
|
: public integral_constant
|
__is_base_of_helper<_Base, _Derived>::__value>
|
__is_base_of_helper<_Base, _Derived>::__value>
|
{ };
|
{ };
|
|
|
template
|
template
|
struct __is_convertible_simple
|
struct __is_convertible_simple
|
: public __sfinae_types
|
: public __sfinae_types
|
{
|
{
|
private:
|
private:
|
static __one __test(_To);
|
static __one __test(_To);
|
static __two __test(...);
|
static __two __test(...);
|
static _From __makeFrom();
|
static _From __makeFrom();
|
|
|
public:
|
public:
|
static const bool __value = sizeof(__test(__makeFrom())) == 1;
|
static const bool __value = sizeof(__test(__makeFrom())) == 1;
|
};
|
};
|
|
|
template
|
template
|
struct add_reference;
|
struct add_reference;
|
|
|
template
|
template
|
struct __is_int_or_cref
|
struct __is_int_or_cref
|
{
|
{
|
typedef typename remove_reference<_Tp>::type __rr_Tp;
|
typedef typename remove_reference<_Tp>::type __rr_Tp;
|
static const bool __value = (is_integral<_Tp>::value
|
static const bool __value = (is_integral<_Tp>::value
|
|| (is_integral<__rr_Tp>::value
|
|| (is_integral<__rr_Tp>::value
|
&& is_const<__rr_Tp>::value
|
&& is_const<__rr_Tp>::value
|
&& !is_volatile<__rr_Tp>::value));
|
&& !is_volatile<__rr_Tp>::value));
|
};
|
};
|
|
|
template
|
template
|
bool = (is_void<_From>::value || is_void<_To>::value
|
bool = (is_void<_From>::value || is_void<_To>::value
|
|| is_function<_To>::value || is_array<_To>::value
|
|| is_function<_To>::value || is_array<_To>::value
|
// This special case is here only to avoid warnings.
|
// This special case is here only to avoid warnings.
|
|| (is_floating_point
|
|| (is_floating_point
|
remove_reference<_From>::type>::value
|
remove_reference<_From>::type>::value
|
&& __is_int_or_cref<_To>::__value))>
|
&& __is_int_or_cref<_To>::__value))>
|
struct __is_convertible_helper
|
struct __is_convertible_helper
|
{
|
{
|
// "An imaginary lvalue of type From...".
|
// "An imaginary lvalue of type From...".
|
static const bool __value = (__is_convertible_simple
|
static const bool __value = (__is_convertible_simple
|
add_reference<_From>::type, _To>::__value);
|
add_reference<_From>::type, _To>::__value);
|
};
|
};
|
|
|
template
|
template
|
struct __is_convertible_helper<_From, _To, true>
|
struct __is_convertible_helper<_From, _To, true>
|
{ static const bool __value = (is_void<_To>::value
|
{ static const bool __value = (is_void<_To>::value
|
|| (__is_int_or_cref<_To>::__value
|
|| (__is_int_or_cref<_To>::__value
|
&& !is_void<_From>::value)); };
|
&& !is_void<_From>::value)); };
|
|
|
template
|
template
|
struct is_convertible
|
struct is_convertible
|
: public integral_constant
|
: public integral_constant
|
__is_convertible_helper<_From, _To>::__value>
|
__is_convertible_helper<_From, _To>::__value>
|
{ };
|
{ };
|
|
|
// reference modifications [4.7.2].
|
// reference modifications [4.7.2].
|
template
|
template
|
struct remove_reference
|
struct remove_reference
|
{ typedef _Tp type; };
|
{ typedef _Tp type; };
|
|
|
template
|
template
|
struct remove_reference<_Tp&>
|
struct remove_reference<_Tp&>
|
{ typedef _Tp type; };
|
{ typedef _Tp type; };
|
|
|
// NB: Careful with reference to void.
|
// NB: Careful with reference to void.
|
template::value
|
template::value
|
|| is_reference<_Tp>::value)>
|
|| is_reference<_Tp>::value)>
|
struct __add_reference_helper
|
struct __add_reference_helper
|
{ typedef _Tp& type; };
|
{ typedef _Tp& type; };
|
|
|
template
|
template
|
struct __add_reference_helper<_Tp, true>
|
struct __add_reference_helper<_Tp, true>
|
{ typedef _Tp type; };
|
{ typedef _Tp type; };
|
|
|
template
|
template
|
struct add_reference
|
struct add_reference
|
: public __add_reference_helper<_Tp>
|
: public __add_reference_helper<_Tp>
|
{ };
|
{ };
|
|
|
// other transformations [4.8].
|
// other transformations [4.8].
|
template
|
template
|
struct aligned_storage
|
struct aligned_storage
|
{
|
{
|
union type
|
union type
|
{
|
{
|
unsigned char __data[_Len];
|
unsigned char __data[_Len];
|
struct __attribute__((__aligned__((_Align)))) { } __align;
|
struct __attribute__((__aligned__((_Align)))) { } __align;
|
};
|
};
|
};
|
};
|
|
|
#undef _DEFINE_SPEC
|
#undef _DEFINE_SPEC
|
}
|
}
|
}
|
}
|
|
|
#endif // _GLIBCXX_TR1_TYPE_TRAITS
|
#endif // _GLIBCXX_TR1_TYPE_TRAITS
|
|
|