type_traits: updated with checks that cv-void specialisations are working correctly

[SVN r8727]
This commit is contained in:
John Maddock
2001-01-23 11:44:44 +00:00
parent f6c5afb5b6
commit 905a17a1c1
8 changed files with 65 additions and 12 deletions

View File

@@ -33,6 +33,7 @@ int main(int argc, char* argv[])
//align_test(const int);
align_test(VB);
align_test(VD);
value_test(0, ::boost::alignment_of<void>::value);
return check_result(argc, argv);
}

View File

@@ -43,6 +43,7 @@ int main(int argc, char* argv[])
value_test(true, boost::is_array<UDT[2]>::value)
value_test(false, boost::is_array<int(&)[2]>::value)
value_test(false, boost::is_array<f1>::value)
value_test(false, boost::is_array<void>::value)
value_test(false, boost::is_pointer<int>::value)
value_test(false, boost::is_pointer<int&>::value)
@@ -60,6 +61,7 @@ int main(int argc, char* argv[])
value_test(false, boost::is_pointer<int(&)[2]>::value)
value_test(false, boost::is_pointer<int[2]>::value)
value_test(false, boost::is_pointer<char[sizeof(void*)]>::value)
value_test(false, boost::is_pointer<void>::value)
value_test(true, boost::is_pointer<f1>::value)
value_test(true, boost::is_pointer<f2>::value)
@@ -78,6 +80,7 @@ int main(int argc, char* argv[])
value_test(true, boost::is_reference<r_type>::value)
value_test(true, boost::is_reference<cr_type>::value)
value_test(true, boost::is_reference<const UDT&>::value)
value_test(false, boost::is_reference<void>::value)
value_test(false, boost::is_member_pointer<f1>::value)
value_test(false, boost::is_member_pointer<f2>::value)
@@ -87,11 +90,13 @@ int main(int argc, char* argv[])
value_test(true, boost::is_member_pointer<mf2>::value)
value_test(true, boost::is_member_pointer<mf3>::value)
value_test(true, boost::is_member_pointer<mf4>::value)
value_test(false, boost::is_member_pointer<void>::value)
value_test(false, boost::is_enum<int>::value)
value_test(true, boost::is_enum<enum_UDT>::value)
value_test(false, boost::is_enum<int_convertible>::value)
value_test(false, boost::is_enum<int&>::value)
value_test(false, boost::is_enum<void>::value)
return check_result(argc, argv);
}

View File

@@ -52,12 +52,28 @@ struct alignment_of
// that a reference is just a special pointer:
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class T>
class alignment_of<T&>
struct alignment_of<T&>
{
public:
BOOST_DECL_MC(std::size_t, value, alignment_of<T*>::value);
};
#endif
//
// void has to be treated specially:
template <>
struct alignment_of<void>
{ BOOST_DECL_MC(std::size_t, value, 0); };
#ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
template <>
struct alignment_of<const void>
{ BOOST_DECL_MC(std::size_t, value, 0); };
template <>
struct alignment_of<volatile void>
{ BOOST_DECL_MC(std::size_t, value, 0); };
template <>
struct alignment_of<const volatile void>
{ BOOST_DECL_MC(std::size_t, value, 0); };
#endif
} // namespace boost

View File

@@ -51,15 +51,15 @@ struct ice_or<false, false, false, false, false, false, false>
BOOST_DECL_MC(bool, value, false);
};
template <bool b1, bool b2, bool b3 = true, bool b4 = true, bool b5 = true>
template <bool b1, bool b2, bool b3 = true, bool b4 = true, bool b5 = true, bool b6 = true, bool b7 = true>
struct ice_and;
template <bool b1, bool b2, bool b3, bool b4, bool b5>
template <bool b1, bool b2, bool b3, bool b4, bool b5, bool b6, bool b7>
struct ice_and
{
BOOST_DECL_MC(bool, value, false);
};
template <>
struct ice_and<true, true, true, true, true>
struct ice_and<true, true, true, true, true, true, true>
{
BOOST_DECL_MC(bool, value, true);
};

View File

@@ -109,6 +109,7 @@ template <typename T> struct is_POD
BOOST_DECL_MC(bool, value,
(::boost::type_traits::ice_or<
::boost::is_scalar<T>::value,
::boost::is_void<T>::value,
BOOST_IS_POD(T)
>::value));
};
@@ -282,17 +283,21 @@ template <typename T>
struct is_empty
{
private:
typedef detail::empty_helper_chooser<
!is_convertible<T,int>::value
& !is_convertible<T,double>::value
& !is_pointer<T>::value
& !is_member_pointer<T>::value
& !is_array<T>::value
& !is_convertible<T, const volatile void*>::value> chooser;
typedef ::boost::detail::empty_helper_chooser<
::boost::type_traits::ice_and<
!::boost::is_convertible<T,int>::value,
!::boost::is_convertible<T,double>::value,
!::boost::is_pointer<T>::value,
!::boost::is_member_pointer<T>::value,
!::boost::is_array<T>::value,
!::boost::is_void<T>::value,
!::boost::is_convertible<T, const volatile void*>::value
>::value> chooser;
typedef typename chooser::template rebind<T> bound_type;
typedef typename bound_type::type eh_type;
public:
enum{ value = eh_type::value | BOOST_IS_EMPTY(T) };
BOOST_DECL_MC(bool, value,
(::boost::type_traits::ice_or<eh_type::value, BOOST_IS_EMPTY(T)>::value));
};
#else

View File

@@ -24,11 +24,19 @@ int main(int argc, char* argv[])
value_test(false, (::boost::is_same<int, int[2]>::value))
value_test(false, (::boost::is_same<int*, int[2]>::value))
value_test(false, (::boost::is_same<int[4], int[2]>::value))
value_test(false, (::boost::is_same<void, int>::value))
value_test(true, (::boost::is_same<void, void>::value))
value_test(false, (::boost::is_same<void, const void>::value))
return check_result(argc, argv);
}
//
// define the number of failures expected for given compilers:
#ifdef BOOST_MSVC
// can't separate void and cv-void:
unsigned int expected_failures = 1;
#else
unsigned int expected_failures = 0;
#endif

View File

@@ -50,6 +50,7 @@ int main(int argc, char* argv[])
value_test(false, boost::is_class<UDT*>::value)
value_test(false, boost::is_class<UDT[2]>::value)
value_test(false, boost::is_class<UDT&>::value)
value_test(false, boost::is_class<void>::value)
value_test(true, boost::is_object<int>::value)
value_test(true, boost::is_object<UDT>::value)
@@ -82,6 +83,7 @@ int main(int argc, char* argv[])
value_test(false, boost::is_POD<UDT>::value)
value_test(false, boost::is_POD<empty_UDT>::value)
value_test(true, boost::is_POD<enum_UDT>::value)
value_test(true, boost::is_POD<void>::value)
value_test(true, boost::has_trivial_constructor<int>::value)
value_test(true, boost::has_trivial_constructor<int*>::value)
@@ -96,6 +98,7 @@ int main(int argc, char* argv[])
value_test(false, boost::has_trivial_constructor<UDT>::value)
value_test(true, boost::has_trivial_constructor<empty_UDT>::value)
value_test(true, boost::has_trivial_constructor<enum_UDT>::value)
value_test(true, boost::has_trivial_constructor<void>::value)
value_test(true, boost::has_trivial_copy<int>::value)
value_test(true, boost::has_trivial_copy<int*>::value)
@@ -111,6 +114,7 @@ int main(int argc, char* argv[])
value_test(false, boost::has_trivial_copy<UDT>::value)
value_test(true, boost::has_trivial_copy<empty_UDT>::value)
value_test(true, boost::has_trivial_copy<enum_UDT>::value)
value_test(true, boost::has_trivial_copy<void>::value)
value_test(true, boost::has_trivial_assign<int>::value)
value_test(true, boost::has_trivial_assign<int*>::value)
@@ -126,6 +130,7 @@ int main(int argc, char* argv[])
value_test(false, boost::has_trivial_assign<UDT>::value)
value_test(true, boost::has_trivial_assign<empty_UDT>::value)
value_test(true, boost::has_trivial_assign<enum_UDT>::value)
value_test(true, boost::has_trivial_assign<void>::value)
value_test(true, boost::has_trivial_destructor<int>::value)
value_test(true, boost::has_trivial_destructor<int*>::value)
@@ -140,10 +145,12 @@ int main(int argc, char* argv[])
value_test(false, boost::has_trivial_destructor<UDT>::value)
value_test(false, boost::has_trivial_destructor<empty_UDT>::value)
value_test(true, boost::has_trivial_destructor<enum_UDT>::value)
value_test(true, boost::has_trivial_destructor<void>::value)
soft_value_test(false, boost::is_empty<int>::value)
soft_value_test(false, boost::is_empty<int*>::value)
soft_value_test(false, boost::is_empty<int&>::value)
soft_value_test(false, boost::is_empty<void>::value)
#if defined(__MWERKS__)
// apparent compiler bug causes this to fail to compile:
value_fail(false, boost::is_empty<int[2]>::value)

View File

@@ -21,11 +21,17 @@ int main(int argc, char* argv[])
type_test(volatile int, boost::remove_const<const volatile int>::type)
type_test(int, boost::remove_const<int>::type)
type_test(int*, boost::remove_const<int* const>::type)
type_test(void, boost::remove_const<const void>::type)
type_test(void, boost::remove_const<void>::type)
type_test(int, boost::remove_volatile<volatile int>::type)
type_test(const int, boost::remove_volatile<const int>::type)
type_test(const int, boost::remove_volatile<const volatile int>::type)
type_test(int, boost::remove_volatile<int>::type)
type_test(int*, boost::remove_volatile<int* volatile>::type)
type_test(void, boost::remove_volatile<volatile void>::type)
type_test(void, boost::remove_volatile<void>::type)
type_test(int, boost::remove_cv<volatile int>::type)
type_test(int, boost::remove_cv<const int>::type)
type_test(int, boost::remove_cv<const volatile int>::type)
@@ -34,6 +40,8 @@ int main(int argc, char* argv[])
type_test(int*, boost::remove_cv<int* const>::type)
type_test(int*, boost::remove_cv<int* const volatile>::type)
type_test(const int *, boost::remove_cv<const int * const>::type)
type_test(void, boost::remove_cv<volatile void>::type)
type_test(void, boost::remove_cv<void>::type)
type_test(int, boost::remove_reference<int>::type)
type_test(const int, boost::remove_reference<const int>::type)
@@ -41,10 +49,12 @@ int main(int argc, char* argv[])
type_test(const int, boost::remove_reference<const int&>::type)
type_test(volatile int, boost::remove_reference<volatile int&>::type)
type_test(int, boost::remove_reference<cr_type>::type)
type_test(void, boost::remove_reference<void>::type)
type_test(int, boost::remove_bounds<int>::type)
type_test(int*, boost::remove_bounds<int*>::type)
type_test(int, boost::remove_bounds<int[3]>::type)
type_test(void, boost::remove_bounds<void>::type)
type_test(int[3], boost::remove_bounds<int[2][3]>::type)
type_test(int, boost::remove_pointer<int>::type)
@@ -54,6 +64,7 @@ int main(int argc, char* argv[])
type_test(volatile int, boost::remove_pointer<volatile int*const volatile>::type)
type_test(int[3], boost::remove_pointer<int[3]>::type)
type_test(int[2][3], boost::remove_pointer<int[2][3]>::type)
type_test(void, boost::remove_pointer<void>::type)
type_test(int&, boost::add_reference<int>::type)
type_test(const int&, boost::add_reference<const int>::type)