// C++0x type_traits -*- C++ -*-
// Copyright (C) 2007-2015 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 3, 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.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// 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;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// .
// ????????????????????????????????????????????????????????????????????
//
// This is a copy of the libstdc++ header, with the trivial modification
// of ignoring the c++config.h include. If and when the top-level build is
// fixed so that target libraries can be built using the newly built, we can
// delete this file.
//
// ????????????????????????????????????????????????????????????????????
/** @file include/type_traits
* This is a Standard C++ Library header.
*/
#ifndef _GLIBCXX_TYPE_TRAITS
#define _GLIBCXX_TYPE_TRAITS 1
// #pragma GCC system_header
// #ifndef __GXX_EXPERIMENTAL_CXX0X__
// # include
// #else
// #include
namespace std // _GLIBCXX_VISIBILITY(default)
{
// _GLIBCXX_BEGIN_NAMESPACE_VERSION
/**
* @addtogroup metaprogramming
* @{
*/
/// integral_constant
template
struct integral_constant
{
static constexpr _Tp value = __v;
typedef _Tp value_type;
typedef integral_constant<_Tp, __v> type;
constexpr operator value_type() { return value; }
};
/// typedef for true_type
typedef integral_constant true_type;
/// typedef for false_type
typedef integral_constant false_type;
template
constexpr _Tp integral_constant<_Tp, __v>::value;
// Meta programming helper types.
template
struct conditional;
template
struct __or_;
template<>
struct __or_<>
: public false_type
{ };
template
struct __or_<_B1>
: public _B1
{ };
template
struct __or_<_B1, _B2>
: public conditional<_B1::value, _B1, _B2>::type
{ };
template
struct __or_<_B1, _B2, _B3, _Bn...>
: public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type
{ };
template
struct __and_;
template<>
struct __and_<>
: public true_type
{ };
template
struct __and_<_B1>
: public _B1
{ };
template
struct __and_<_B1, _B2>
: public conditional<_B1::value, _B2, _B1>::type
{ };
template
struct __and_<_B1, _B2, _B3, _Bn...>
: public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type
{ };
template
struct __not_
: public integral_constant
{ };
struct __sfinae_types
{
typedef char __one;
typedef struct { char __arr[2]; } __two;
};
// primary type categories.
template
struct remove_cv;
template
struct __is_void_helper
: public false_type { };
template<>
struct __is_void_helper
: public true_type { };
/// is_void
template
struct is_void
: public integral_constant::type>::value)>
{ };
template
struct __is_integral_helper
: public false_type { };
template<>
struct __is_integral_helper
: public true_type { };
template<>
struct __is_integral_helper
: public true_type { };
template<>
struct __is_integral_helper
: public true_type { };
template<>
struct __is_integral_helper
: public true_type { };
#ifdef _GLIBCXX_USE_WCHAR_T
template<>
struct __is_integral_helper
: public true_type { };
#endif
template<>
struct __is_integral_helper
: public true_type { };
template<>
struct __is_integral_helper
: public true_type { };
template<>
struct __is_integral_helper
: public true_type { };
template<>
struct __is_integral_helper
: public true_type { };
template<>
struct __is_integral_helper
: public true_type { };
template<>
struct __is_integral_helper
: public true_type { };
template<>
struct __is_integral_helper
: public true_type { };
template<>
struct __is_integral_helper
: public true_type { };
template<>
struct __is_integral_helper
: public true_type { };
template<>
struct __is_integral_helper
: public true_type { };
#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
template<>
struct __is_integral_helper<__int128>
: public true_type { };
template<>
struct __is_integral_helper
: public true_type { };
#endif
/// is_integral
template
struct is_integral
: public integral_constant::type>::value)>
{ };
template
struct __is_floating_point_helper
: public false_type { };
template<>
struct __is_floating_point_helper
: public true_type { };
template<>
struct __is_floating_point_helper
: public true_type { };
template<>
struct __is_floating_point_helper
: public true_type { };
#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
template<>
struct __is_floating_point_helper<__float128>
: public true_type { };
#endif
/// is_floating_point
template
struct is_floating_point
: public integral_constant::type>::value)>
{ };
/// is_array
template
struct is_array
: public false_type { };
template
struct is_array<_Tp[_Size]>
: public true_type { };
template
struct is_array<_Tp[]>
: public true_type { };
template
struct __is_pointer_helper
: public false_type { };
template
struct __is_pointer_helper<_Tp*>
: public true_type { };
/// is_pointer
template
struct is_pointer
: public integral_constant::type>::value)>
{ };
/// is_lvalue_reference
template
struct is_lvalue_reference
: public false_type { };
template
struct is_lvalue_reference<_Tp&>
: public true_type { };
/// is_rvalue_reference
template
struct is_rvalue_reference
: public false_type { };
template
struct is_rvalue_reference<_Tp&&>
: public true_type { };
template
struct is_function;
template
struct __is_member_object_pointer_helper
: public false_type { };
template
struct __is_member_object_pointer_helper<_Tp _Cp::*>
: public integral_constant::value> { };
/// is_member_object_pointer
template
struct is_member_object_pointer
: public integral_constant::type>::value)>
{ };
template
struct __is_member_function_pointer_helper
: public false_type { };
template
struct __is_member_function_pointer_helper<_Tp _Cp::*>
: public integral_constant::value> { };
/// is_member_function_pointer
template
struct is_member_function_pointer
: public integral_constant::type>::value)>
{ };
/// is_enum
template
struct is_enum
: public integral_constant
{ };
/// is_union
template
struct is_union
: public integral_constant
{ };
/// is_class
template
struct is_class
: public integral_constant
{ };
/// is_function
template
struct is_function
: public false_type { };
template
struct is_function<_Res(_ArgTypes...)>
: public true_type { };
template
struct is_function<_Res(_ArgTypes......)>
: public true_type { };
template
struct is_function<_Res(_ArgTypes...) const>
: public true_type { };
template
struct is_function<_Res(_ArgTypes......) const>
: public true_type { };
template
struct is_function<_Res(_ArgTypes...) volatile>
: public true_type { };
template
struct is_function<_Res(_ArgTypes......) volatile>
: public true_type { };
template
struct is_function<_Res(_ArgTypes...) const volatile>
: public true_type { };
template
struct is_function<_Res(_ArgTypes......) const volatile>
: public true_type { };
template
struct __is_nullptr_t_helper
: public false_type { };
#if 0
template<>
struct __is_nullptr_t_helper
: public true_type { };
#endif
// __is_nullptr_t (extension).
template
struct __is_nullptr_t
: public integral_constant::type>::value)>
{ };
// composite type categories.
/// is_reference
template
struct is_reference
: public __or_,
is_rvalue_reference<_Tp>>::type
{ };
/// is_arithmetic
template
struct is_arithmetic
: public __or_, is_floating_point<_Tp>>::type
{ };
/// is_fundamental
template
struct is_fundamental
: public __or_, is_void<_Tp>>::type
{ };
/// is_object
template
struct is_object
: public __not_<__or_, is_reference<_Tp>,
is_void<_Tp>>>::type
{ };
template
struct is_member_pointer;
/// is_scalar
template
struct is_scalar
: public __or_, is_enum<_Tp>, is_pointer<_Tp>,
is_member_pointer<_Tp>, __is_nullptr_t<_Tp>>::type
{ };
/// is_compound
template
struct is_compound
: public integral_constant::value> { };
/// is_member_pointer
template
struct __is_member_pointer_helper
: public false_type { };
template
struct __is_member_pointer_helper<_Tp _Cp::*>
: public true_type { };
template
struct is_member_pointer
: public integral_constant::type>::value)>
{ };
// type properties.
/// is_const
template
struct is_const
: public false_type { };
template
struct is_const<_Tp const>
: public true_type { };
/// is_volatile
template
struct is_volatile
: public false_type { };
template
struct is_volatile<_Tp volatile>
: public true_type { };
/// is_trivial
template
struct is_trivial
: public integral_constant
{ };
/// is_trivially_copyable (still unimplemented)
/// is_standard_layout
template
struct is_standard_layout
: public integral_constant
{ };
/// is_pod
// Could use is_standard_layout && is_trivial instead of the builtin.
template
struct is_pod
: public integral_constant
{ };
/// is_literal_type
template
struct is_literal_type
: public integral_constant
{ };
/// is_empty
template
struct is_empty
: public integral_constant
{ };
/// is_polymorphic
template
struct is_polymorphic
: public integral_constant
{ };
/// is_abstract
template
struct is_abstract
: public integral_constant
{ };
template::value,
bool = is_floating_point<_Tp>::value>
struct __is_signed_helper
: public false_type { };
template
struct __is_signed_helper<_Tp, false, true>
: public true_type { };
template
struct __is_signed_helper<_Tp, true, false>
: public integral_constant(_Tp(-1) < _Tp(0))>
{ };
/// is_signed
template
struct is_signed
: public integral_constant::value>
{ };
/// is_unsigned
template
struct is_unsigned
: public __and_, __not_>>::type
{ };
// destructible and constructible type properties
template
struct add_rvalue_reference;
template
typename add_rvalue_reference<_Tp>::type declval() noexcept;
template
struct extent;
template
struct remove_all_extents;
template
struct __is_array_known_bounds
: public integral_constant::value > 0)>
{ };
template
struct __is_array_unknown_bounds
: public __and_, __not_>>::type
{ };
// In N3290 is_destructible does not say anything about function
// types and abstract types, see LWG 2049. This implementation
// describes function types as trivially nothrow destructible and
// abstract types as destructible, iff the explicit destructor
// call expression is wellformed.
struct __do_is_destructible_impl_1
{
template
struct __w { _Up __u; };
template&>().~__w<_Tp>())>
static true_type __test(int);
template
static false_type __test(...);
};
template
struct __is_destructible_impl_1
: public __do_is_destructible_impl_1
{
typedef decltype(__test<_Tp>(0)) type;
};
// Special implementation for abstract types
struct __do_is_destructible_impl_2
{
template().~_Tp())>
static true_type __test(int);
template
static false_type __test(...);
};
template
struct __is_destructible_impl_2
: public __do_is_destructible_impl_2
{
typedef decltype(__test<_Tp>(0)) type;
};
template,
__is_array_unknown_bounds<_Tp>>::value,
bool = __or_, is_function<_Tp>>::value>
struct __is_destructible_safe;
template
struct __is_destructible_safe<_Tp, false, false>
: public conditional::value,
__is_destructible_impl_2<_Tp>,
__is_destructible_impl_1<_Tp>>::type::type
{ };
template
struct __is_destructible_safe<_Tp, true, false>
: public false_type { };
template
struct __is_destructible_safe<_Tp, false, true>
: public true_type { };
/// is_destructible
template
struct is_destructible
: public integral_constant::value)>
{ };
struct __do_is_default_constructible_impl
{
template
static true_type __test(int);
template
static false_type __test(...);
};
template
struct __is_default_constructible_impl
: public __do_is_default_constructible_impl
{
typedef decltype(__test<_Tp>(0)) type;
};
template
struct __is_default_constructible_atom
: public __and_<__not_>,
__is_default_constructible_impl<_Tp>>::type
{ };
template::value>
struct __is_default_constructible_safe;
// The following technique is a workaround for a current core language
// restriction, which does not allow for array types to occur in
// functional casts of the form T(). Complete arrays can be default-
// constructed, if the element type is default-constructible, but
// arrays with unknown bounds are not.
template
struct __is_default_constructible_safe<_Tp, true>
: public __and_<__is_array_known_bounds<_Tp>,
__is_default_constructible_atom::type>>::type
{ };
template
struct __is_default_constructible_safe<_Tp, false>
: public __is_default_constructible_atom<_Tp>::type
{ };
/// is_default_constructible
template
struct is_default_constructible
: public integral_constant::value)>
{ };
// Implementation of is_constructible.
// The hardest part of this trait is the binary direct-initialization
// case, because we hit into a functional cast of the form T(arg).
// This implementation uses different strategies depending on the
// target type to reduce the test overhead as much as possible:
//
// a) For a reference target type, we use a static_cast expression
// modulo its extra cases.
//
// b) For a non-reference target type we use a ::new expression.
struct __do_is_static_castable_impl
{
template(declval<_From>()))>
static true_type __test(int);
template
static false_type __test(...);
};
template
struct __is_static_castable_impl
: public __do_is_static_castable_impl
{
typedef decltype(__test<_From, _To>(0)) type;
};
template
struct __is_static_castable_safe
: public __is_static_castable_impl<_From, _To>::type
{ };
// __is_static_castable
template
struct __is_static_castable
: public integral_constant::value)>
{ };
// Implementation for non-reference types. To meet the proper
// variable definition semantics, we also need to test for
// is_destructible in this case.
struct __do_is_direct_constructible_impl
{
template()))>
static true_type __test(int);
template
static false_type __test(...);
};
template
struct __is_direct_constructible_impl
: public __do_is_direct_constructible_impl
{
typedef decltype(__test<_Tp, _Arg>(0)) type;
};
template
struct __is_direct_constructible_new_safe
: public __and_,
__is_direct_constructible_impl<_Tp, _Arg>>::type
{ };
template
struct is_same;
template
struct is_base_of;
template
struct remove_reference;
template::value>
struct __is_base_to_derived_ref;
template
struct __is_base_to_derived_ref<_From, _To, true>
{
typedef typename remove_cv::type>::type __src_t;
typedef typename remove_cv::type>::type __dst_t;
typedef __and_<__not_>,
is_base_of<__src_t, __dst_t>> type;
static constexpr bool value = type::value;
};
template
struct __is_base_to_derived_ref<_From, _To, false>
: public false_type
{ };
template,
is_rvalue_reference<_To>>::value>
struct __is_lvalue_to_rvalue_ref;
template
struct __is_lvalue_to_rvalue_ref<_From, _To, true>
{
typedef typename remove_cv::type>::type __src_t;
typedef typename remove_cv::type>::type __dst_t;
typedef __or_,
is_base_of<__dst_t, __src_t>> type;
static constexpr bool value = type::value;
};
template
struct __is_lvalue_to_rvalue_ref<_From, _To, false>
: public false_type
{ };
// Here we handle direct-initialization to a reference type as
// equivalent to a static_cast modulo overshooting conversions.
// These are restricted to the following conversions:
// a) A glvalue of a base class to a derived class reference
// b) An lvalue to an rvalue-reference of reference-compatible
// types
template
struct __is_direct_constructible_ref_cast
: public __and_<__is_static_castable<_Arg, _Tp>,
__not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>,
__is_lvalue_to_rvalue_ref<_Arg, _Tp>
>>>::type
{ };
template
struct __is_direct_constructible_new
: public conditional::value,
__is_direct_constructible_ref_cast<_Tp, _Arg>,
__is_direct_constructible_new_safe<_Tp, _Arg>
>::type
{ };
template
struct __is_direct_constructible
: public integral_constant::value)>
{ };
// Since default-construction and binary direct-initialization have
// been handled separately, the implementation of the remaining
// n-ary construction cases is rather straightforward.
struct __do_is_nary_constructible_impl
{
template()...))>
static true_type __test(int);
template
static false_type __test(...);
};
template
struct __is_nary_constructible_impl
: public __do_is_nary_constructible_impl
{
typedef decltype(__test<_Tp, _Args...>(0)) type;
};
template
struct __is_nary_constructible
: public __is_nary_constructible_impl<_Tp, _Args...>::type
{
static_assert(sizeof...(_Args) > 1,
"Only useful for > 1 arguments");
};
template
struct __is_constructible_impl
: public __is_nary_constructible<_Tp, _Args...>
{ };
template
struct __is_constructible_impl<_Tp, _Arg>
: public __is_direct_constructible<_Tp, _Arg>
{ };
template
struct __is_constructible_impl<_Tp>
: public is_default_constructible<_Tp>
{ };
/// is_constructible
template
struct is_constructible
: public integral_constant::value)>
{ };
template::value>
struct __is_copy_constructible_impl;
template
struct __is_copy_constructible_impl<_Tp, true>
: public false_type { };
template
struct __is_copy_constructible_impl<_Tp, false>
: public is_constructible<_Tp, const _Tp&>
{ };
/// is_copy_constructible
template
struct is_copy_constructible
: public __is_copy_constructible_impl<_Tp>
{ };
template::value>
struct __is_move_constructible_impl;
template
struct __is_move_constructible_impl<_Tp, true>
: public false_type { };
template
struct __is_move_constructible_impl<_Tp, false>
: public is_constructible<_Tp, _Tp&&>
{ };
/// is_move_constructible
template
struct is_move_constructible
: public __is_move_constructible_impl<_Tp>
{ };
template
struct __is_nt_default_constructible_atom
: public integral_constant
{ };
template::value>
struct __is_nt_default_constructible_impl;
template
struct __is_nt_default_constructible_impl<_Tp, true>
: public __and_<__is_array_known_bounds<_Tp>,
__is_nt_default_constructible_atom::type>>::type
{ };
template
struct __is_nt_default_constructible_impl<_Tp, false>
: public __is_nt_default_constructible_atom<_Tp>
{ };
/// is_nothrow_default_constructible
template
struct is_nothrow_default_constructible
: public __and_,
__is_nt_default_constructible_impl<_Tp>>::type
{ };
template
struct __is_nt_constructible_impl
: public integral_constant()...))>
{ };
template
struct __is_nt_constructible_impl<_Tp, _Arg>
: public integral_constant(declval<_Arg>()))>
{ };
template
struct __is_nt_constructible_impl<_Tp>
: public is_nothrow_default_constructible<_Tp>
{ };
/// is_nothrow_constructible
template
struct is_nothrow_constructible
: public __and_,
__is_nt_constructible_impl<_Tp, _Args...>>::type
{ };
template::value>
struct __is_nothrow_copy_constructible_impl;
template
struct __is_nothrow_copy_constructible_impl<_Tp, true>
: public false_type { };
template
struct __is_nothrow_copy_constructible_impl<_Tp, false>
: public is_nothrow_constructible<_Tp, const _Tp&>
{ };
/// is_nothrow_copy_constructible
template
struct is_nothrow_copy_constructible
: public __is_nothrow_copy_constructible_impl<_Tp>
{ };
template::value>
struct __is_nothrow_move_constructible_impl;
template
struct __is_nothrow_move_constructible_impl<_Tp, true>
: public false_type { };
template
struct __is_nothrow_move_constructible_impl<_Tp, false>
: public is_nothrow_constructible<_Tp, _Tp&&>
{ };
/// is_nothrow_move_constructible
template
struct is_nothrow_move_constructible
: public __is_nothrow_move_constructible_impl<_Tp>
{ };
template
class __is_assignable_helper
: public __sfinae_types
{
template
static decltype(declval<_Tp1>() = declval<_Up1>(), __one())
__test(int);
template
static __two __test(...);
public:
static constexpr bool value = sizeof(__test<_Tp, _Up>(0)) == 1;
};
/// is_assignable
template
struct is_assignable
: public integral_constant::value>
{ };
template::value>
struct __is_copy_assignable_impl;
template
struct __is_copy_assignable_impl<_Tp, true>
: public false_type { };
template
struct __is_copy_assignable_impl<_Tp, false>
: public is_assignable<_Tp&, const _Tp&>
{ };
/// is_copy_assignable
template
struct is_copy_assignable
: public __is_copy_assignable_impl<_Tp>
{ };
template::value>
struct __is_move_assignable_impl;
template
struct __is_move_assignable_impl<_Tp, true>
: public false_type { };
template
struct __is_move_assignable_impl<_Tp, false>
: public is_assignable<_Tp&, _Tp&&>
{ };
/// is_move_assignable
template
struct is_move_assignable
: public __is_move_assignable_impl<_Tp>
{ };
template
struct __is_nt_assignable_impl
: public integral_constant() = declval<_Up>())>
{ };
/// is_nothrow_assignable
template
struct is_nothrow_assignable
: public __and_