From 0ab92896c6dfea4861a9687607ea521852c72686 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Tue, 24 Mar 2009 13:35:49 +0000 Subject: [PATCH] Added has_new_operator from Robert Ramey. [SVN r51955] --- .../boost/type_traits/has_new_operator.hpp | 113 +++++++++++ test/has_operator_new_test.cpp | 181 ++++++++++++++++++ 2 files changed, 294 insertions(+) create mode 100644 include/boost/type_traits/has_new_operator.hpp create mode 100644 test/has_operator_new_test.cpp diff --git a/include/boost/type_traits/has_new_operator.hpp b/include/boost/type_traits/has_new_operator.hpp new file mode 100644 index 0000000..13cd167 --- /dev/null +++ b/include/boost/type_traits/has_new_operator.hpp @@ -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 +#include +#include + +// should be the last #include +#include + +namespace boost { +namespace detail { + template + struct test; + + template + struct has_new_operator_impl { + template + static type_traits::yes_type check_sig( + U*, + test< + void *(*)(std::size_t), + &U::operator new + >* = NULL + ); + template + static type_traits::yes_type check_sig( + U*, + test< + void *(*)(std::size_t, const std::nothrow_t&), + &U::operator new + >* = NULL + ); + template + static type_traits::yes_type check_sig( + U*, + test< + void *(*)(std::size_t, void*), + &U::operator new + >* = NULL + ); + template + static type_traits::no_type check_sig(...); + + template + static type_traits::yes_type check_sig2( + U*, + test< + void *(*)(std::size_t), + &U::operator new[] + >* = NULL + ); + template + static type_traits::yes_type check_sig2( + U*, + test< + void *(*)(std::size_t, const std::nothrow_t&), + &U::operator new[] + >* = NULL + ); + template + static type_traits::yes_type check_sig2( + U*, + test< + void *(*)(std::size_t, void*), + &U::operator new[] + >* = NULL + ); + template + 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::template check_sig(0))); + BOOST_STATIC_CONSTANT(unsigned, s2 = sizeof(has_new_operator_impl::template check_sig2(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(0))); + BOOST_STATIC_CONSTANT(unsigned, s2 = sizeof(check_sig2(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::value) + +} // namespace boost + +#include + +#endif // BOOST_TT_HAS_NEW_OPERATOR_HPP_INCLUDED diff --git a/test/has_operator_new_test.cpp b/test/has_operator_new_test.cpp new file mode 100644 index 0000000..d9e9349 --- /dev/null +++ b/test/has_operator_new_test.cpp @@ -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 + +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::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::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::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int8>::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int8 const>::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int8 volatile>::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int8 const volatile>::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int16>::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int16 const>::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int16 volatile>::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int16 const volatile>::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int32>::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int32 const>::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int32 volatile>::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int32 const volatile>::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int64>::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int64 const>::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int64 volatile>::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator<__int64 const volatile>::value, false); + +#endif + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); + +TT_TEST_END