Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51955 - in trunk: boost/type_traits libs/type_traits/test
From: john_at_[hidden]
Date: 2009-03-24 09:35:49


Author: johnmaddock
Date: 2009-03-24 09:35:49 EDT (Tue, 24 Mar 2009)
New Revision: 51955
URL: http://svn.boost.org/trac/boost/changeset/51955

Log:
Added has_new_operator from Robert Ramey.
Added:
   trunk/boost/type_traits/has_new_operator.hpp (contents, props changed)
   trunk/libs/type_traits/test/has_operator_new_test.cpp (contents, props changed)

Added: trunk/boost/type_traits/has_new_operator.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/type_traits/has_new_operator.hpp 2009-03-24 09:35:49 EDT (Tue, 24 Mar 2009)
@@ -0,0 +1,113 @@
+
+// (C) Copyright Runar Undheim, Robert Ramey & John Maddock 2008.
+// Use, modification and distribution are subject to the Boost Software License,
+// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt).
+//
+// See http://www.boost.org/libs/type_traits for most recent version including documentation.
+
+#ifndef BOOST_TT_HAS_NEW_OPERATOR_HPP_INCLUDED
+#define BOOST_TT_HAS_NEW_OPERATOR_HPP_INCLUDED
+
+#include <boost/type_traits/config.hpp>
+#include <boost/type_traits/detail/yes_no_type.hpp>
+#include <boost/type_traits/detail/ice_or.hpp>
+
+// should be the last #include
+#include <boost/type_traits/detail/bool_trait_def.hpp>
+
+namespace boost {
+namespace detail {
+ template <class U, U x>
+ struct test;
+
+ template <typename T>
+ struct has_new_operator_impl {
+ template<class U>
+ static type_traits::yes_type check_sig(
+ U*,
+ test<
+ void *(*)(std::size_t),
+ &U::operator new
+ >* = NULL
+ );
+ template<class U>
+ static type_traits::yes_type check_sig(
+ U*,
+ test<
+ void *(*)(std::size_t, const std::nothrow_t&),
+ &U::operator new
+ >* = NULL
+ );
+ template<class U>
+ static type_traits::yes_type check_sig(
+ U*,
+ test<
+ void *(*)(std::size_t, void*),
+ &U::operator new
+ >* = NULL
+ );
+ template<class U>
+ static type_traits::no_type check_sig(...);
+
+ template<class U>
+ static type_traits::yes_type check_sig2(
+ U*,
+ test<
+ void *(*)(std::size_t),
+ &U::operator new[]
+ >* = NULL
+ );
+ template<class U>
+ static type_traits::yes_type check_sig2(
+ U*,
+ test<
+ void *(*)(std::size_t, const std::nothrow_t&),
+ &U::operator new[]
+ >* = NULL
+ );
+ template<class U>
+ static type_traits::yes_type check_sig2(
+ U*,
+ test<
+ void *(*)(std::size_t, void*),
+ &U::operator new[]
+ >* = NULL
+ );
+ template<class U>
+ static type_traits::no_type check_sig2(...);
+
+ // GCC2 won't even parse this template if we embed the computation
+ // of s1 in the computation of value.
+ #ifdef __GNUC__
+ BOOST_STATIC_CONSTANT(unsigned, s1 = sizeof(has_new_operator_impl<T>::template check_sig<T>(0)));
+ BOOST_STATIC_CONSTANT(unsigned, s2 = sizeof(has_new_operator_impl<T>::template check_sig2<T>(0)));
+ #else
+ #if BOOST_WORKAROUND(_MSC_FULL_VER, >= 140050000)
+ #pragma warning(push)
+ #pragma warning(disable:6334)
+ #endif
+
+ BOOST_STATIC_CONSTANT(unsigned, s1 = sizeof(check_sig<T>(0)));
+ BOOST_STATIC_CONSTANT(unsigned, s2 = sizeof(check_sig2<T>(0)));
+
+ #if BOOST_WORKAROUND(_MSC_FULL_VER, >= 140050000)
+ #pragma warning(pop)
+ #endif
+ #endif
+ BOOST_STATIC_CONSTANT(bool, value =
+ (::boost::type_traits::ice_or<
+ (s1 == sizeof(type_traits::yes_type)),
+ (s2 == sizeof(type_traits::yes_type))
+ >::value)
+ );
+ };
+} // namespace detail
+
+BOOST_TT_AUX_BOOL_TRAIT_DEF1(has_new_operator,T,::boost::detail::has_new_operator_impl<T>::value)
+
+} // namespace boost
+
+#include <boost/type_traits/detail/bool_trait_undef.hpp>
+
+#endif // BOOST_TT_HAS_NEW_OPERATOR_HPP_INCLUDED

Added: trunk/libs/type_traits/test/has_operator_new_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/type_traits/test/has_operator_new_test.cpp 2009-03-24 09:35:49 EDT (Tue, 24 Mar 2009)
@@ -0,0 +1,181 @@
+// (C) Copyright John Maddock 2000.
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include "test.hpp"
+#include "check_integral_constant.hpp"
+#include <boost/type_traits/has_new_operator.hpp>
+
+struct class_with_new_op {
+ void * operator new(std::size_t);
+};
+
+struct derived_class_with_new_op : public class_with_new_op {};
+
+struct class_with_new_op2 {
+ void* operator new(std::size_t size, const std::nothrow_t&);
+};
+
+struct class_with_new_op3 {
+ void* operator new[](std::size_t size);
+};
+
+struct class_with_new_op4 {
+ void* operator new[](std::size_t size, const std::nothrow_t&);
+};
+
+struct class_with_new_op5 {
+ void* operator new (std::size_t size, void* ptr);
+};
+
+struct class_with_new_op6 {
+ void* operator new[] (std::size_t size, void* ptr);
+};
+
+TT_TEST_BEGIN(has_new_operator)
+
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<class_with_new_op>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<derived_class_with_new_op>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<class_with_new_op2>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<class_with_new_op3>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<class_with_new_op4>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<class_with_new_op5>::value, true);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<class_with_new_op6>::value, true);
+
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<bool>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<bool const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<bool volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<bool const volatile>::value, false);
+
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<signed char>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<signed char const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<signed char volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<signed char const volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned char>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<char>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned char const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<char const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned char volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<char volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned char const volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<char const volatile>::value, false);
+
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned short>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<short>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned short const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<short const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned short volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<short volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned short const volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<short const volatile>::value, false);
+
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned int>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<int>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned int const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<int const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned int volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<int volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned int const volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<int const volatile>::value, false);
+
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned long>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<long>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned long const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<long const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned long volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<long volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned long const volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<long const volatile>::value, false);
+
+#ifdef BOOST_HAS_LONG_LONG
+
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator< ::boost::ulong_long_type>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator< ::boost::long_long_type>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator< ::boost::ulong_long_type const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator< ::boost::long_long_type const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator< ::boost::ulong_long_type volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator< ::boost::long_long_type volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator< ::boost::ulong_long_type const volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator< ::boost::long_long_type const volatile>::value, false);
+
+#endif
+
+#ifdef BOOST_HAS_MS_INT64
+
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned __int8>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int8>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned __int8 const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int8 const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned __int8 volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int8 volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned __int8 const volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int8 const volatile>::value, false);
+
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned __int16>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int16>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned __int16 const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int16 const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned __int16 volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int16 volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned __int16 const volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int16 const volatile>::value, false);
+
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned __int32>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int32>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned __int32 const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int32 const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned __int32 volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int32 volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned __int32 const volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int32 const volatile>::value, false);
+
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned __int64>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int64>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned __int64 const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int64 const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned __int64 volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int64 volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<unsigned __int64 const volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int64 const volatile>::value, false);
+
+#endif
+
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<float>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<float const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<float volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<float const volatile>::value, false);
+
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<double>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<double const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<double volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<double const volatile>::value, false);
+
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<long double>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<long double const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<long double volatile>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<long double const volatile>::value, false);
+
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<int>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<void*>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<int*const>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<f1>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<f2>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<f3>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<mf1>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<mf2>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<mf3>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<mp>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<cmf>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<enum_UDT>::value, false);
+
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<int&>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<const int&>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<int[2]>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<int[3][2]>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<int[2][4][5][6][3]>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<UDT>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<empty_UDT>::value, false);
+BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<void>::value, false);
+
+TT_TEST_END


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk