diff --git a/include/boost/unordered/detail/allocator_helpers.hpp b/include/boost/unordered/detail/allocate.hpp similarity index 55% rename from include/boost/unordered/detail/allocator_helpers.hpp rename to include/boost/unordered/detail/allocate.hpp index 82f1b185..3084edc2 100644 --- a/include/boost/unordered/detail/allocator_helpers.hpp +++ b/include/boost/unordered/detail/allocate.hpp @@ -1,23 +1,510 @@ // Copyright 2005-2011 Daniel James. // Copyright 2009 Pablo Halpern. -// // Distributed under 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) -// -// Allocator traits written by Daniel James based on Pablo Halpern's -// implementation. -#ifndef BOOST_UNORDERED_DETAIL_ALLOCATOR_UTILITIES_HPP_INCLUDED -#define BOOST_UNORDERED_DETAIL_ALLOCATOR_UTILITIES_HPP_INCLUDED +// See http://www.boost.org/libs/unordered for documentation + +#ifndef BOOST_UNORDERED_ALLOCATE_HPP +#define BOOST_UNORDERED_ALLOCATE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include + +#if !defined(BOOST_NO_0X_HDR_TUPLE) +#include +#endif + +#if defined(BOOST_MSVC) +#pragma warning(push) +#pragma warning(disable:4512) // assignment operator could not be generated. +#pragma warning(disable:4345) // behavior change: an object of POD type + // constructed with an initializer of the form () + // will be default-initialized. +#endif + +#define BOOST_UNORDERED_EMPLACE_LIMIT 10 + +namespace boost { namespace unordered { namespace detail { + + //////////////////////////////////////////////////////////////////////////// + // Bits and pieces for implementing traits + + template typename boost::add_lvalue_reference::type make(); + struct choice9 { typedef char (&type)[9]; }; + struct choice8 : choice9 { typedef char (&type)[8]; }; + struct choice7 : choice8 { typedef char (&type)[7]; }; + struct choice6 : choice7 { typedef char (&type)[6]; }; + struct choice5 : choice6 { typedef char (&type)[5]; }; + struct choice4 : choice5 { typedef char (&type)[4]; }; + struct choice3 : choice4 { typedef char (&type)[3]; }; + struct choice2 : choice3 { typedef char (&type)[2]; }; + struct choice1 : choice2 { typedef char (&type)[1]; }; + choice1 choose(); + + typedef choice1::type yes_type; + typedef choice2::type no_type; + + struct private_type + { + private_type const &operator,(int) const; + }; + + template + no_type is_private_type(T const&); + yes_type is_private_type(private_type const&); + + struct convert_from_anything { + template + convert_from_anything(T const&); + }; + + //////////////////////////////////////////////////////////////////////////// + // emplace_args + // + // Either forwarding variadic arguments, or storing the arguments in + // emplace_args##n + +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) + +#define BOOST_UNORDERED_EMPLACE_TEMPLATE typename... Args +#define BOOST_UNORDERED_EMPLACE_ARGS BOOST_FWD_REF(Args)... args +#define BOOST_UNORDERED_EMPLACE_FORWARD boost::forward(args)... + +#define BOOST_UNORDERED_EMPLACE_ARGS1(a0) a0 +#define BOOST_UNORDERED_EMPLACE_ARGS2(a0, a1) a0, a1 +#define BOOST_UNORDERED_EMPLACE_ARGS3(a0, a1, a2) a0, a1, a2 + +#else + +#define BOOST_UNORDERED_EMPLACE_TEMPLATE typename Args +#define BOOST_UNORDERED_EMPLACE_ARGS Args const& args +#define BOOST_UNORDERED_EMPLACE_FORWARD args + +#define BOOST_UNORDERED_FWD_PARAM(z, n, a) \ + BOOST_FWD_REF(BOOST_PP_CAT(A, n)) BOOST_PP_CAT(a, n) + +#define BOOST_UNORDERED_CALL_FORWARD(z, i, a) \ + boost::forward(BOOST_PP_CAT(a,i)) + +#define BOOST_UNORDERED_EARGS(z, n, _) \ + template \ + struct BOOST_PP_CAT(emplace_args, n) \ + { \ + BOOST_PP_REPEAT_##z(n, BOOST_UNORDERED_EARGS_MEMBER, _) \ + BOOST_PP_CAT(emplace_args, n) ( \ + BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, Arg, b) \ + ) : BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_EARGS_INIT, _) \ + {} \ + \ + }; \ + \ + template \ + inline BOOST_PP_CAT(emplace_args, n) < \ + BOOST_PP_ENUM_PARAMS_Z(z, n, A) \ + > create_emplace_args( \ + BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, b) \ + ) \ + { \ + BOOST_PP_CAT(emplace_args, n) < \ + BOOST_PP_ENUM_PARAMS_Z(z, n, A) \ + > e(BOOST_PP_ENUM_PARAMS_Z(z, n, b)); \ + return e; \ + } + +#define BOOST_UNORDERED_EMPLACE_ARGS1 create_emplace_args +#define BOOST_UNORDERED_EMPLACE_ARGS2 create_emplace_args +#define BOOST_UNORDERED_EMPLACE_ARGS3 create_emplace_args + +#if defined(BOOST_NO_RVALUE_REFERENCES) + +#define BOOST_UNORDERED_EARGS_MEMBER(z, n, _) \ + typedef BOOST_FWD_REF(BOOST_PP_CAT(A, n)) BOOST_PP_CAT(Arg, n); \ + BOOST_PP_CAT(Arg, n) BOOST_PP_CAT(a, n); + +#define BOOST_UNORDERED_EARGS_INIT(z, n, _) \ + BOOST_PP_CAT(a, n)( \ + boost::forward(BOOST_PP_CAT(b, n))) + +#else + +#define BOOST_UNORDERED_EARGS_MEMBER(z, n, _) \ + typedef typename boost::add_lvalue_reference::type \ + BOOST_PP_CAT(Arg, n); \ + BOOST_PP_CAT(Arg, n) BOOST_PP_CAT(a, n); + +#define BOOST_UNORDERED_EARGS_INIT(z, n, _) \ + BOOST_PP_CAT(a, n)(BOOST_PP_CAT(b, n)) + +#endif + +BOOST_PP_REPEAT_FROM_TO(1, BOOST_UNORDERED_EMPLACE_LIMIT, BOOST_UNORDERED_EARGS, + _) + +#undef BOOST_UNORDERED_DEFINE_EMPLACE_ARGS +#undef BOOST_UNORDERED_EARGS_MEMBER +#undef BOOST_UNORDERED_EARGS_INIT + +#endif + + //////////////////////////////////////////////////////////////////////////// + // rvalue parameters when type can't be a BOOST_RV_REF(T) parameter + // e.g. for int + +#if !defined(BOOST_NO_RVALUE_REFERENCES) +# define BOOST_UNORDERED_RV_REF(T) BOOST_RV_REF(T) +#else + struct please_ignore_this_overload { + typedef please_ignore_this_overload type; + }; + + template + struct rv_ref_impl { + typedef BOOST_RV_REF(T) type; + }; + + template + struct rv_ref : + boost::detail::if_true< + boost::is_class::value + >::BOOST_NESTED_TEMPLATE then < + boost::unordered::detail::rv_ref_impl, + please_ignore_this_overload + >::type + {}; + +# define BOOST_UNORDERED_RV_REF(T) \ + typename boost::unordered::detail::rv_ref::type +#endif + + //////////////////////////////////////////////////////////////////////////// + // Construct from tuple + // + // Used for piecewise construction. + +#if !defined(__SUNPRO_CC) + +# define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(n, namespace_) \ + template \ + void construct_from_tuple(T* ptr, namespace_ tuple<>) \ + { \ + new ((void*) ptr) T(); \ + } \ + \ + BOOST_PP_REPEAT_FROM_TO(1, n, \ + BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL, namespace_) + +# define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL(z, n, namespace_) \ + template \ + void construct_from_tuple(T* ptr, \ + namespace_ tuple const& x) \ + { \ + new ((void*) ptr) T( \ + BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_GET_TUPLE_ARG, namespace_) \ + ); \ + } + +# define BOOST_UNORDERED_GET_TUPLE_ARG(z, n, namespace_) \ + namespace_ get(x) + +#else + + template struct length {}; + +# define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(n, namespace_) \ + template \ + void construct_from_tuple_impl( \ + boost::unordered::detail::length<0>, T* ptr, \ + namespace_ tuple<>) \ + { \ + new ((void*) ptr) T(); \ + } \ + \ + BOOST_PP_REPEAT_FROM_TO(1, n, \ + BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL, namespace_) + +# define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL(z, n, namespace_) \ + template \ + void construct_from_tuple_impl( \ + boost::unordered::detail::length, T* ptr, \ + namespace_ tuple const& x) \ + { \ + new ((void*) ptr) T( \ + BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_GET_TUPLE_ARG, namespace_) \ + ); \ + } + +# define BOOST_UNORDERED_GET_TUPLE_ARG(z, n, namespace_) \ + namespace_ get(x) + +#endif + +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(10, boost::) + +#if !defined(__SUNPRO_CC) && !defined(BOOST_NO_0X_HDR_TUPLE) + BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(10, std::) +#endif + +#undef BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE +#undef BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL +#undef BOOST_UNORDERED_GET_TUPLE_ARG + +#if defined(__SUNPRO_CC) + + template + void construct_from_tuple(T* ptr, Tuple const& x) + { + construct_from_tuple_impl( + boost::unordered::detail::length< + boost::tuples::length::value>(), + ptr, x); + } + +#endif + + //////////////////////////////////////////////////////////////////////////// + // SFINAE traits for construction. + + // Decide which construction method to use for a three argument + // call. Note that this is difficult to do using overloads because + // the arguments are packed into 'emplace_args3'. + // + // The decision is made on the first argument. + + +#if defined(BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT) + template + struct emulation1 { + static choice1::type test(choice1, std::pair const&); + static choice2::type test(choice2, A const&); + static choice3::type test(choice3, convert_from_anything const&); + + enum { value = + sizeof(test(choose(), boost::unordered::detail::make())) == + sizeof(choice2::type) }; + }; +#endif + + template + struct check3_base { + static choice1::type test(choice1, + boost::unordered::piecewise_construct_t); + +#if defined(BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT) + static choice2::type test(choice2, A const&); +#endif + + static choice3::type test(choice3, ...); + + enum { value = + sizeof(test(choose(), boost::unordered::detail::make())) }; + }; + + template + struct piecewise3 { + enum { value = check3_base::value == sizeof(choice1::type) }; + }; + +#if defined(BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT) + template + struct emulation3 { + enum { value = check3_base::value == sizeof(choice2::type) }; + }; + +#endif + +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) + + //////////////////////////////////////////////////////////////////////////// + // Construct from variadic parameters + + template + inline void construct_impl(T* address, BOOST_FWD_REF(Args)... args) + { + new((void*) address) T(boost::forward(args)...); + } + + template + inline typename enable_if, void>::type + construct_impl(std::pair* address, A0&&, A1&& a1, A2&& a2) + { + boost::unordered::detail::construct_from_tuple( + boost::addressof(address->first), a1); + boost::unordered::detail::construct_from_tuple( + boost::addressof(address->second), a2); + } + +#if defined(BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT) + + template + inline typename enable_if, void>::type + construct_impl(std::pair* address, A0&& a0) + { + new((void*) boost::addressof(address->first)) A(boost::forward(a0)); + new((void*) boost::addressof(address->second)) B(); + } + + template + inline typename enable_if, void>::type + construct_impl(std::pair* address, A0&& a0, A1&& a1, A2&& a2) + { + new((void*) boost::addressof(address->first)) A(boost::forward(a0)); + new((void*) boost::addressof(address->second)) B( + boost::forward(a1), + boost::forward(a2)); + } + + template + inline void construct_impl(std::pair* address, + A0&& a0, A1&& a1, A2&& a2, A3&& a3, Args&&... args) + { + new((void*) boost::addressof(address->first)) A(boost::forward(a0)); + + new((void*) boost::addressof(address->second)) B( + boost::forward(a1), + boost::forward(a2), + boost::forward(a3), + boost::forward(args)...); + } + +#endif // BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT +#else // BOOST_NO_VARIADIC_TEMPLATES + +//////////////////////////////////////////////////////////////////////////////// +// Construct from emplace_args + +#define BOOST_UNORDERED_CONSTRUCT_IMPL(z, num_params, _) \ + template < \ + typename T, \ + BOOST_PP_ENUM_PARAMS_Z(z, num_params, typename A) \ + > \ + inline void construct_impl(T* address, \ + boost::unordered::detail::BOOST_PP_CAT(emplace_args,num_params) < \ + BOOST_PP_ENUM_PARAMS_Z(z, num_params, A) \ + > const& args) \ + { \ + new((void*) address) T( \ + BOOST_PP_ENUM_##z(num_params, BOOST_UNORDERED_CALL_FORWARD, \ + args.a)); \ + } + + template + inline void construct_impl(T* address, emplace_args1 const& args) + { + new((void*) address) T(boost::forward(args.a0)); + } + + template + inline void construct_impl(T* address, emplace_args2 const& args) + { + new((void*) address) T( + boost::forward(args.a0), + boost::forward(args.a1) + ); + } + + template + inline void construct_impl(T* address, emplace_args3 const& args) + { + new((void*) address) T( + boost::forward(args.a0), + boost::forward(args.a1), + boost::forward(args.a2) + ); + } + + BOOST_PP_REPEAT_FROM_TO(4, BOOST_UNORDERED_EMPLACE_LIMIT, + BOOST_UNORDERED_CONSTRUCT_IMPL, _) + +#undef BOOST_UNORDERED_CONSTRUCT_IMPL + + template + inline typename enable_if, void>::type + construct_impl(std::pair* address, + boost::unordered::detail::emplace_args3 const& args) + { + boost::unordered::detail::construct_from_tuple( + boost::addressof(address->first), args.a1); + boost::unordered::detail::construct_from_tuple( + boost::addressof(address->second), args.a2); + } + +#if defined(BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT) + + template + inline typename enable_if, void>::type + construct_impl(std::pair* address, + boost::unordered::detail::emplace_args1 const& args) + { + new((void*) boost::addressof(address->first)) A( + boost::forward(args.a0)); + new((void*) boost::addressof(address->second)) B(); + } + + template + inline typename enable_if, void>::type + construct_impl(std::pair* address, + boost::unordered::detail::emplace_args3 const& args) + { + new((void*) boost::addressof(address->first)) A( + boost::forward(args.a0)); + new((void*) boost::addressof(address->second)) B( + boost::forward(args.a1), + boost::forward(args.a2)); + } + +#define BOOST_UNORDERED_CONSTRUCT_PAIR_IMPL(z, num_params, _) \ + template \ + inline void construct_impl(std::pair* address, \ + boost::unordered::detail::BOOST_PP_CAT(emplace_args, num_params) < \ + BOOST_PP_ENUM_PARAMS_Z(z, num_params, A) \ + > const& args) \ + { \ + new((void*) boost::addressof(address->first)) A( \ + boost::forward(args.a0)); \ + new((void*) boost::addressof(address->second)) B( \ + BOOST_PP_ENUM_##z(BOOST_PP_DEC(num_params), \ + BOOST_UNORDERED_CALL_FORWARD2, args.a)); \ + } + +#define BOOST_UNORDERED_CALL_FORWARD2(z, i, a) \ + BOOST_UNORDERED_CALL_FORWARD(z, BOOST_PP_INC(i), a) + + BOOST_UNORDERED_CONSTRUCT_PAIR_IMPL(1, 2, _) + BOOST_PP_REPEAT_FROM_TO(4, BOOST_UNORDERED_EMPLACE_LIMIT, + BOOST_UNORDERED_CONSTRUCT_PAIR_IMPL, _) + +#undef BOOST_UNORDERED_CONSTRUCT_PAIR_IMPL +#undef BOOST_UNORDERED_CALL_FORWARD2 + +#endif // BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT +#endif // BOOST_NO_VARIADIC_TEMPLATES + +}}} //////////////////////////////////////////////////////////////////////////////// // @@ -30,7 +517,7 @@ #if !defined(BOOST_UNORDERED_USE_ALLOCATOR_TRAITS) # if defined(__GXX_EXPERIMENTAL_CXX0X__) && \ (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) -# define BOOST_UNORDERED_USE_ALLOCATOR_TRAITS 1 +# define BOOST_UNORDERED_USE_ALLOCATOR_TRAITS 0 # elif defined(BOOST_MSVC) # if BOOST_MSVC < 1400 // Use container's allocator_traits for older versions of Visual @@ -192,7 +679,7 @@ namespace boost { namespace unordered { namespace detail { # include # endif -# if defined(BOOST_UNORDERED_VARIADIC_MOVE) && \ +# if !defined(BOOST_NO_VARIADIC_TEMPLATES) && \ !defined(BOOST_NO_SFINAE_EXPR) # define BOOST_UNORDERED_DETAIL_FULL_CONSTRUCT 1 # else @@ -282,7 +769,7 @@ namespace boost { namespace unordered { namespace detail { max_size, U const, (), 0 ); -# if defined(BOOST_UNORDERED_VARIADIC_MOVE) +# if !defined(BOOST_NO_VARIADIC_TEMPLATES) template BOOST_UNORDERED_HAS_FUNCTION( @@ -409,7 +896,7 @@ namespace boost { namespace unordered { namespace detail { static typename boost::enable_if_c< boost::unordered::detail::has_construct ::value>::type - construct(Alloc& a, T* p, Args&&... x) + construct(Alloc& a, T* p, BOOST_FWD_REF(Args)... x) { a.construct(p, boost::forward(x)...); } @@ -418,7 +905,7 @@ namespace boost { namespace unordered { namespace detail { static typename boost::disable_if_c< boost::unordered::detail::has_construct ::value>::type - construct(Alloc&, T* p, Args&&... x) + construct(Alloc&, T* p, BOOST_FWD_REF(Args)... x) { new ((void*) p) T(boost::forward(x)...); } @@ -577,7 +1064,7 @@ namespace boost { namespace unordered { namespace detail { //////////////////////////////////////////////////////////////////////////////// // // boost::container::allocator_traits - + #elif BOOST_UNORDERED_USE_ALLOCATOR_TRAITS == 2 # include @@ -720,4 +1207,8 @@ namespace boost { namespace unordered { namespace detail { }; }}} +#if defined(BOOST_MSVC) +#pragma warning(pop) +#endif + #endif diff --git a/include/boost/unordered/detail/buckets.hpp b/include/boost/unordered/detail/buckets.hpp index 8f0054f3..85681a68 100644 --- a/include/boost/unordered/detail/buckets.hpp +++ b/include/boost/unordered/detail/buckets.hpp @@ -12,7 +12,7 @@ #endif #include -#include +#include #include #include #include @@ -82,15 +82,11 @@ namespace boost { namespace unordered { namespace detail { void construct_value2(BOOST_FWD_REF(A0) a0) { BOOST_ASSERT(node_ && !constructed_); -# if defined(BOOST_UNORDERED_VARIADIC_MOVE) - boost::unordered::detail::construct_node(alloc_, - boost::addressof(*node_), boost::forward(a0)); -# else + boost::unordered::detail::construct_node(alloc_, boost::addressof(*node_), - boost::unordered::detail::create_emplace_args( - boost::forward(a0))); -# endif + BOOST_UNORDERED_EMPLACE_ARGS1(boost::forward(a0))); + constructed_ = true; node_->init(static_cast(node_)); } diff --git a/include/boost/unordered/detail/emplace_args.hpp b/include/boost/unordered/detail/emplace_args.hpp deleted file mode 100644 index a26dd4ef..00000000 --- a/include/boost/unordered/detail/emplace_args.hpp +++ /dev/null @@ -1,518 +0,0 @@ - -// Copyright (C) 2011 Daniel James. -// Distributed under 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/unordered for documentation - -#ifndef BOOST_UNORDERED_EMPLACE_ARGS_HPP -#define BOOST_UNORDERED_EMPLACE_ARGS_HPP - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if !defined(BOOST_NO_0X_HDR_TUPLE) -#include -#endif - -#if defined(BOOST_MSVC) -#pragma warning(push) -#pragma warning(disable:4512) // assignment operator could not be generated. -#pragma warning(disable:4345) // behavior change: an object of POD type - // constructed with an initializer of the form () - // will be default-initialized. -#endif - -#define BOOST_UNORDERED_EMPLACE_LIMIT 10 - -#if !defined(BOOST_NO_RVALUE_REFERENCES) && \ - !defined(BOOST_NO_VARIADIC_TEMPLATES) -#define BOOST_UNORDERED_VARIADIC_MOVE -#endif - -namespace boost { namespace unordered { namespace detail { - - //////////////////////////////////////////////////////////////////////////// - // Bits and pieces for implementing traits - - template typename boost::add_lvalue_reference::type make(); - struct choice9 { typedef char (&type)[9]; }; - struct choice8 : choice9 { typedef char (&type)[8]; }; - struct choice7 : choice8 { typedef char (&type)[7]; }; - struct choice6 : choice7 { typedef char (&type)[6]; }; - struct choice5 : choice6 { typedef char (&type)[5]; }; - struct choice4 : choice5 { typedef char (&type)[4]; }; - struct choice3 : choice4 { typedef char (&type)[3]; }; - struct choice2 : choice3 { typedef char (&type)[2]; }; - struct choice1 : choice2 { typedef char (&type)[1]; }; - choice1 choose(); - - typedef choice1::type yes_type; - typedef choice2::type no_type; - - struct private_type - { - private_type const &operator,(int) const; - }; - - template - no_type is_private_type(T const&); - yes_type is_private_type(private_type const&); - - struct convert_from_anything { - template - convert_from_anything(T const&); - }; - - //////////////////////////////////////////////////////////////////////////// - // emplace_args - // - // Either forwarding variadic arguments, or storing the arguments in - // emplace_args##n - -#if defined(BOOST_UNORDERED_VARIADIC_MOVE) - -#define BOOST_UNORDERED_EMPLACE_TEMPLATE typename... Args -#define BOOST_UNORDERED_EMPLACE_ARGS Args&&... args -#define BOOST_UNORDERED_EMPLACE_FORWARD boost::forward(args)... - -#else - -#define BOOST_UNORDERED_EMPLACE_TEMPLATE typename Args -#define BOOST_UNORDERED_EMPLACE_ARGS Args const& args -#define BOOST_UNORDERED_EMPLACE_FORWARD args - -#define BOOST_UNORDERED_FWD_PARAM(z, n, a) \ - BOOST_FWD_REF(BOOST_PP_CAT(A, n)) BOOST_PP_CAT(a, n) - -#define BOOST_UNORDERED_CALL_FORWARD(z, i, a) \ - boost::forward(BOOST_PP_CAT(a,i)) - -#define BOOST_UNORDERED_EARGS(z, n, _) \ - template \ - struct BOOST_PP_CAT(emplace_args, n) \ - { \ - BOOST_PP_REPEAT_##z(n, BOOST_UNORDERED_EARGS_MEMBER, _) \ - BOOST_PP_CAT(emplace_args, n) ( \ - BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, Arg, b) \ - ) : BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_EARGS_INIT, _) \ - {} \ - \ - }; \ - \ - template \ - inline BOOST_PP_CAT(emplace_args, n) < \ - BOOST_PP_ENUM_PARAMS_Z(z, n, A) \ - > create_emplace_args( \ - BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, b) \ - ) \ - { \ - BOOST_PP_CAT(emplace_args, n) < \ - BOOST_PP_ENUM_PARAMS_Z(z, n, A) \ - > e(BOOST_PP_ENUM_PARAMS_Z(z, n, b)); \ - return e; \ - } - -#if defined(BOOST_NO_RVALUE_REFERENCES) - -#define BOOST_UNORDERED_EARGS_MEMBER(z, n, _) \ - typedef BOOST_FWD_REF(BOOST_PP_CAT(A, n)) BOOST_PP_CAT(Arg, n); \ - BOOST_PP_CAT(Arg, n) BOOST_PP_CAT(a, n); - -#define BOOST_UNORDERED_EARGS_INIT(z, n, _) \ - BOOST_PP_CAT(a, n)( \ - boost::forward(BOOST_PP_CAT(b, n))) - -#else - -#define BOOST_UNORDERED_EARGS_MEMBER(z, n, _) \ - typedef typename boost::add_lvalue_reference::type \ - BOOST_PP_CAT(Arg, n); \ - BOOST_PP_CAT(Arg, n) BOOST_PP_CAT(a, n); - -#define BOOST_UNORDERED_EARGS_INIT(z, n, _) \ - BOOST_PP_CAT(a, n)(BOOST_PP_CAT(b, n)) - -#endif - -BOOST_PP_REPEAT_FROM_TO(1, BOOST_UNORDERED_EMPLACE_LIMIT, BOOST_UNORDERED_EARGS, - _) - -#undef BOOST_UNORDERED_DEFINE_EMPLACE_ARGS -#undef BOOST_UNORDERED_EARGS_MEMBER -#undef BOOST_UNORDERED_EARGS_INIT - -#endif - - //////////////////////////////////////////////////////////////////////////// - // rvalue parameters when type can't be a BOOST_RV_REF(T) parameter - // e.g. for int - -#if !defined(BOOST_NO_RVALUE_REFERENCES) -# define BOOST_UNORDERED_RV_REF(T) BOOST_RV_REF(T) -#else - struct please_ignore_this_overload { - typedef please_ignore_this_overload type; - }; - - template - struct rv_ref_impl { - typedef BOOST_RV_REF(T) type; - }; - - template - struct rv_ref : - boost::detail::if_true< - boost::is_class::value - >::BOOST_NESTED_TEMPLATE then < - boost::unordered::detail::rv_ref_impl, - please_ignore_this_overload - >::type - {}; - -# define BOOST_UNORDERED_RV_REF(T) \ - typename boost::unordered::detail::rv_ref::type -#endif - - //////////////////////////////////////////////////////////////////////////// - // Construct from tuple - // - // Used for piecewise construction. - -#if !defined(__SUNPRO_CC) - -# define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(n, namespace_) \ - template \ - void construct_from_tuple(T* ptr, namespace_ tuple<>) \ - { \ - new ((void*) ptr) T(); \ - } \ - \ - BOOST_PP_REPEAT_FROM_TO(1, n, \ - BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL, namespace_) - -# define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL(z, n, namespace_) \ - template \ - void construct_from_tuple(T* ptr, \ - namespace_ tuple const& x) \ - { \ - new ((void*) ptr) T( \ - BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_GET_TUPLE_ARG, namespace_) \ - ); \ - } - -# define BOOST_UNORDERED_GET_TUPLE_ARG(z, n, namespace_) \ - namespace_ get(x) - -#else - - template struct length {}; - -# define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(n, namespace_) \ - template \ - void construct_from_tuple_impl( \ - boost::unordered::detail::length<0>, T* ptr, \ - namespace_ tuple<>) \ - { \ - new ((void*) ptr) T(); \ - } \ - \ - BOOST_PP_REPEAT_FROM_TO(1, n, \ - BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL, namespace_) - -# define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL(z, n, namespace_) \ - template \ - void construct_from_tuple_impl( \ - boost::unordered::detail::length, T* ptr, \ - namespace_ tuple const& x) \ - { \ - new ((void*) ptr) T( \ - BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_GET_TUPLE_ARG, namespace_) \ - ); \ - } - -# define BOOST_UNORDERED_GET_TUPLE_ARG(z, n, namespace_) \ - namespace_ get(x) - -#endif - -BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(10, boost::) - -#if !defined(__SUNPRO_CC) && !defined(BOOST_NO_0X_HDR_TUPLE) - BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(10, std::) -#endif - -#undef BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE -#undef BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL -#undef BOOST_UNORDERED_GET_TUPLE_ARG - -#if defined(__SUNPRO_CC) - - template - void construct_from_tuple(T* ptr, Tuple const& x) - { - construct_from_tuple_impl( - boost::unordered::detail::length< - boost::tuples::length::value>(), - ptr, x); - } - -#endif - - //////////////////////////////////////////////////////////////////////////// - // SFINAE traits for construction. - - // Decide which construction method to use for a three argument - // call. Note that this is difficult to do using overloads because - // the arguments are packed into 'emplace_args3'. - // - // The decision is made on the first argument. - - -#if defined(BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT) - template - struct emulation1 { - static choice1::type test(choice1, std::pair const&); - static choice2::type test(choice2, A const&); - static choice3::type test(choice3, convert_from_anything const&); - - enum { value = - sizeof(test(choose(), boost::unordered::detail::make())) == - sizeof(choice2::type) }; - }; -#endif - - template - struct check3_base { - static choice1::type test(choice1, - boost::unordered::piecewise_construct_t); - -#if defined(BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT) - static choice2::type test(choice2, A const&); -#endif - - static choice3::type test(choice3, ...); - - enum { value = - sizeof(test(choose(), boost::unordered::detail::make())) }; - }; - - template - struct piecewise3 { - enum { value = check3_base::value == sizeof(choice1::type) }; - }; - -#if defined(BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT) - template - struct emulation3 { - enum { value = check3_base::value == sizeof(choice2::type) }; - }; - -#endif - -#if defined(BOOST_UNORDERED_VARIADIC_MOVE) - - //////////////////////////////////////////////////////////////////////////// - // Construct from variadic parameters - - template - inline void construct_impl(T* address, Args&&... args) - { - new((void*) address) T(boost::forward(args)...); - } - - template - inline typename enable_if, void>::type - construct_impl(std::pair* address, A0&&, A1&& a1, A2&& a2) - { - boost::unordered::detail::construct_from_tuple( - boost::addressof(address->first), a1); - boost::unordered::detail::construct_from_tuple( - boost::addressof(address->second), a2); - } - -#if defined(BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT) - - template - inline typename enable_if, void>::type - construct_impl(std::pair* address, A0&& a0) - { - new((void*) boost::addressof(address->first)) A(boost::forward(a0)); - new((void*) boost::addressof(address->second)) B(); - } - - template - inline typename enable_if, void>::type - construct_impl(std::pair* address, A0&& a0, A1&& a1, A2&& a2) - { - new((void*) boost::addressof(address->first)) A(boost::forward(a0)); - new((void*) boost::addressof(address->second)) B( - boost::forward(a1), - boost::forward(a2)); - } - - template - inline void construct_impl(std::pair* address, - A0&& a0, A1&& a1, A2&& a2, A3&& a3, Args&&... args) - { - new((void*) boost::addressof(address->first)) A(boost::forward(a0)); - - new((void*) boost::addressof(address->second)) B( - boost::forward(a1), - boost::forward(a2), - boost::forward(a3), - boost::forward(args)...); - } - -#endif // BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT -#else // BOOST_UNORDERED_VARIADIC_MOVE - -//////////////////////////////////////////////////////////////////////////////// -// Construct from emplace_args - -#define BOOST_UNORDERED_CONSTRUCT_IMPL(z, num_params, _) \ - template < \ - typename T, \ - BOOST_PP_ENUM_PARAMS_Z(z, num_params, typename A) \ - > \ - inline void construct_impl(T* address, \ - boost::unordered::detail::BOOST_PP_CAT(emplace_args,num_params) < \ - BOOST_PP_ENUM_PARAMS_Z(z, num_params, A) \ - > const& args) \ - { \ - new((void*) address) T( \ - BOOST_PP_ENUM_##z(num_params, BOOST_UNORDERED_CALL_FORWARD, \ - args.a)); \ - } - - template - inline void construct_impl(T* address, emplace_args1 const& args) - { - new((void*) address) T(boost::forward(args.a0)); - } - - template - inline void construct_impl(T* address, emplace_args2 const& args) - { - new((void*) address) T( - boost::forward(args.a0), - boost::forward(args.a1) - ); - } - - template - inline void construct_impl(T* address, emplace_args3 const& args) - { - new((void*) address) T( - boost::forward(args.a0), - boost::forward(args.a1), - boost::forward(args.a2) - ); - } - - BOOST_PP_REPEAT_FROM_TO(4, BOOST_UNORDERED_EMPLACE_LIMIT, - BOOST_UNORDERED_CONSTRUCT_IMPL, _) - -#undef BOOST_UNORDERED_CONSTRUCT_IMPL - - template - inline typename enable_if, void>::type - construct_impl(std::pair* address, - boost::unordered::detail::emplace_args3 const& args) - { - boost::unordered::detail::construct_from_tuple( - boost::addressof(address->first), args.a1); - boost::unordered::detail::construct_from_tuple( - boost::addressof(address->second), args.a2); - } - -#if defined(BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT) - - template - inline typename enable_if, void>::type - construct_impl(std::pair* address, - boost::unordered::detail::emplace_args1 const& args) - { - new((void*) boost::addressof(address->first)) A( - boost::forward(args.a0)); - new((void*) boost::addressof(address->second)) B(); - } - - template - inline typename enable_if, void>::type - construct_impl(std::pair* address, - boost::unordered::detail::emplace_args3 const& args) - { - new((void*) boost::addressof(address->first)) A( - boost::forward(args.a0)); - new((void*) boost::addressof(address->second)) B( - boost::forward(args.a1), - boost::forward(args.a2)); - } - -#define BOOST_UNORDERED_CONSTRUCT_PAIR_IMPL(z, num_params, _) \ - template \ - inline void construct_impl(std::pair* address, \ - boost::unordered::detail::BOOST_PP_CAT(emplace_args, num_params) < \ - BOOST_PP_ENUM_PARAMS_Z(z, num_params, A) \ - > const& args) \ - { \ - new((void*) boost::addressof(address->first)) A( \ - boost::forward(args.a0)); \ - new((void*) boost::addressof(address->second)) B( \ - BOOST_PP_ENUM_##z(BOOST_PP_DEC(num_params), \ - BOOST_UNORDERED_CALL_FORWARD2, args.a)); \ - } - -#define BOOST_UNORDERED_CALL_FORWARD2(z, i, a) \ - BOOST_UNORDERED_CALL_FORWARD(z, BOOST_PP_INC(i), a) - - BOOST_UNORDERED_CONSTRUCT_PAIR_IMPL(1, 2, _) - BOOST_PP_REPEAT_FROM_TO(4, BOOST_UNORDERED_EMPLACE_LIMIT, - BOOST_UNORDERED_CONSTRUCT_PAIR_IMPL, _) - -#undef BOOST_UNORDERED_CONSTRUCT_PAIR_IMPL -#undef BOOST_UNORDERED_CALL_FORWARD2 - -#endif // BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT -#endif // BOOST_UNORDERED_VARIADIC_MOVE - - //////////////////////////////////////////////////////////////////////////// - // Construct without using the emplace args mechanism. - - template - inline void construct_impl2(T* address, BOOST_FWD_REF(A0) a0) - { - new((void*) address) T( - boost::forward(a0) - ); - } - -}}} - -#if defined(BOOST_MSVC) -#pragma warning(pop) -#endif - -#endif diff --git a/include/boost/unordered/detail/equivalent.hpp b/include/boost/unordered/detail/equivalent.hpp index 6df3c03a..74a4205a 100644 --- a/include/boost/unordered/detail/equivalent.hpp +++ b/include/boost/unordered/detail/equivalent.hpp @@ -497,12 +497,21 @@ namespace boost { namespace unordered { namespace detail { } #if defined(BOOST_NO_RVALUE_REFERENCES) +# if defined(BOOST_NO_VARIADIC_TEMPLATES) iterator emplace(boost::unordered::detail::emplace_args1< boost::unordered::detail::please_ignore_this_overload> const&) { BOOST_ASSERT(false); return iterator(); } +# else + iterator emplace( + boost::unordered::detail::please_ignore_this_overload const&) + { + BOOST_ASSERT(false); + return iterator(); + } +# endif #endif template diff --git a/include/boost/unordered/detail/extract_key.hpp b/include/boost/unordered/detail/extract_key.hpp index 4ca13e8c..99232893 100644 --- a/include/boost/unordered/detail/extract_key.hpp +++ b/include/boost/unordered/detail/extract_key.hpp @@ -56,7 +56,7 @@ namespace detail { return no_key(); } -#if defined(BOOST_UNORDERED_VARIADIC_MOVE) +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) template static no_key extract(Args const&...) { @@ -111,7 +111,7 @@ namespace detail { return v.first; } -#if defined(BOOST_UNORDERED_VARIADIC_MOVE) +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) template static key_type const& extract(key_type const& k, Arg1 const&, Args const&...) @@ -150,12 +150,12 @@ namespace detail { } #endif -#if defined(BOOST_UNORDERED_VARIADIC_MOVE) +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) #define BOOST_UNORDERED_KEY_FROM_TUPLE(namespace_) \ template \ static no_key extract(boost::unordered::piecewise_construct_t, \ - namespace_::tuple<> const&, T2&&) \ + namespace_::tuple<> const&, BOOST_FWD_REF(T2)) \ { \ return no_key(); \ } \ @@ -163,7 +163,7 @@ namespace detail { template \ static typename is_key::type \ extract(boost::unordered::piecewise_construct_t, \ - namespace_::tuple const& k, T2&&) \ + namespace_::tuple const& k, BOOST_FWD_REF(T2)) \ { \ return typename is_key::type( \ namespace_::get<0>(k)); \ diff --git a/include/boost/unordered/detail/unique.hpp b/include/boost/unordered/detail/unique.hpp index 8628591e..e7777183 100644 --- a/include/boost/unordered/detail/unique.hpp +++ b/include/boost/unordered/detail/unique.hpp @@ -379,38 +379,41 @@ namespace boost { namespace unordered { namespace detail { // exception (need strong safety in such a case). node_constructor a(this->node_alloc()); a.construct_node(); -#if defined(BOOST_UNORDERED_VARIADIC_MOVE) - a.construct_value(boost::unordered::piecewise_construct, - boost::make_tuple(k), boost::make_tuple()); -#else - a.construct_value( - boost::unordered::detail::create_emplace_args( - boost::unordered::piecewise_construct, - boost::make_tuple(k), - boost::make_tuple())); -#endif + + a.construct_value(BOOST_UNORDERED_EMPLACE_ARGS3( + boost::unordered::piecewise_construct, + boost::make_tuple(k), + boost::make_tuple())); this->reserve_for_insert(this->size_ + 1); return *add_node(a, key_hash); } #if defined(BOOST_NO_RVALUE_REFERENCES) +# if defined(BOOST_NO_VARIADIC_TEMPLATES) emplace_return emplace(boost::unordered::detail::emplace_args1< boost::unordered::detail::please_ignore_this_overload> const&) { BOOST_ASSERT(false); return emplace_return(this->begin(), false); } +# else + emplace_return emplace( + boost::unordered::detail::please_ignore_this_overload const&) + { + BOOST_ASSERT(false); + return emplace_return(this->begin(), false); + } +# endif #endif template emplace_return emplace(BOOST_UNORDERED_EMPLACE_ARGS) { -#if defined(BOOST_UNORDERED_VARIADIC_MOVE) +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) return emplace_impl( extractor::extract(BOOST_UNORDERED_EMPLACE_FORWARD), BOOST_UNORDERED_EMPLACE_FORWARD); - #else return emplace_impl( extractor::extract(args.a0, args.a1), @@ -418,7 +421,7 @@ namespace boost { namespace unordered { namespace detail { #endif } -#if !defined(BOOST_UNORDERED_VARIADIC_MOVE) +#if defined(BOOST_NO_VARIADIC_TEMPLATES) template emplace_return emplace( boost::unordered::detail::emplace_args1 const& args) diff --git a/include/boost/unordered/unordered_map.hpp b/include/boost/unordered/unordered_map.hpp index 8e6621d4..9bbb687b 100644 --- a/include/boost/unordered/unordered_map.hpp +++ b/include/boost/unordered/unordered_map.hpp @@ -14,7 +14,6 @@ #endif #include -#include #include #include #include @@ -233,15 +232,15 @@ namespace unordered // emplace -#if defined(BOOST_UNORDERED_VARIADIC_MOVE) +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) template - std::pair emplace(Args&&... args) + std::pair emplace(BOOST_FWD_REF(Args)... args) { return table_.emplace(boost::forward(args)...); } template - iterator emplace_hint(const_iterator, Args&&... args) + iterator emplace_hint(const_iterator, BOOST_FWD_REF(Args)... args) { return table_.emplace(boost::forward(args)...).first; } @@ -720,15 +719,15 @@ namespace unordered // emplace -#if defined(BOOST_UNORDERED_VARIADIC_MOVE) +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) template - iterator emplace(Args&&... args) + iterator emplace(BOOST_FWD_REF(Args)... args) { return table_.emplace(boost::forward(args)...); } template - iterator emplace_hint(const_iterator, Args&&... args) + iterator emplace_hint(const_iterator, BOOST_FWD_REF(Args)... args) { return table_.emplace(boost::forward(args)...); } diff --git a/include/boost/unordered/unordered_set.hpp b/include/boost/unordered/unordered_set.hpp index a85a1676..a33251fb 100644 --- a/include/boost/unordered/unordered_set.hpp +++ b/include/boost/unordered/unordered_set.hpp @@ -14,7 +14,6 @@ #endif #include -#include #include #include #include @@ -231,15 +230,15 @@ namespace unordered // emplace -#if defined(BOOST_UNORDERED_VARIADIC_MOVE) +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) template - std::pair emplace(Args&&... args) + std::pair emplace(BOOST_FWD_REF(Args)... args) { return table_.emplace(boost::forward(args)...); } template - iterator emplace_hint(const_iterator, Args&&... args) + iterator emplace_hint(const_iterator, BOOST_FWD_REF(Args)... args) { return table_.emplace(boost::forward(args)...).first; } @@ -704,15 +703,15 @@ namespace unordered // emplace -#if defined(BOOST_UNORDERED_VARIADIC_MOVE) +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) template - iterator emplace(Args&&... args) + iterator emplace(BOOST_FWD_REF(Args)... args) { return table_.emplace(boost::forward(args)...); } template - iterator emplace_hint(const_iterator, Args&&... args) + iterator emplace_hint(const_iterator, BOOST_FWD_REF(Args)... args) { return table_.emplace(boost::forward(args)...); } diff --git a/test/exception/insert_exception_tests.cpp b/test/exception/insert_exception_tests.cpp index 1d3ee67a..464a0ff5 100644 --- a/test/exception/insert_exception_tests.cpp +++ b/test/exception/insert_exception_tests.cpp @@ -32,7 +32,7 @@ struct insert_test_base : public test::exception_base std::string scope(test::scope); if(scope.find("hash::operator()") == std::string::npos) - strong.test(x, test::exception::detail::tracker.count_allocations); + strong.test(x, test::detail::tracker.count_allocations); test::check_equivalent_keys(x); } }; @@ -49,7 +49,7 @@ struct emplace_test1 : public insert_test_base it = this->values.begin(), end = this->values.end(); it != end; ++it) { - strong.store(x, test::exception::detail::tracker.count_allocations); + strong.store(x, test::detail::tracker.count_allocations); x.emplace(*it); } } @@ -67,7 +67,7 @@ struct insert_test1 : public insert_test_base it = this->values.begin(), end = this->values.end(); it != end; ++it) { - strong.store(x, test::exception::detail::tracker.count_allocations); + strong.store(x, test::detail::tracker.count_allocations); x.insert(*it); } } @@ -83,7 +83,7 @@ struct insert_test2 : public insert_test_base it = this->values.begin(), end = this->values.end(); it != end; ++it) { - strong.store(x, test::exception::detail::tracker.count_allocations); + strong.store(x, test::detail::tracker.count_allocations); x.insert(x.begin(), *it); } } @@ -111,7 +111,7 @@ struct insert_test4 : public insert_test_base it = this->values.begin(), end = this->values.end(); it != end; ++it) { - strong.store(x, test::exception::detail::tracker.count_allocations); + strong.store(x, test::detail::tracker.count_allocations); x.insert(it, boost::next(it)); } } @@ -150,7 +150,7 @@ struct insert_test_rehash1 : public insert_test_base end = this->values.end(); it != end && count < 10; ++it, ++count) { - strong.store(x, test::exception::detail::tracker.count_allocations); + strong.store(x, test::detail::tracker.count_allocations); pos = x.insert(pos, *it); } @@ -174,7 +174,7 @@ struct insert_test_rehash2 : public insert_test_rehash1 end = this->values.end(); it != end && count < 10; ++it, ++count) { - strong.store(x, test::exception::detail::tracker.count_allocations); + strong.store(x, test::detail::tracker.count_allocations); x.insert(*it); } diff --git a/test/helpers/allocator.hpp b/test/helpers/allocator.hpp deleted file mode 100644 index 5482baa0..00000000 --- a/test/helpers/allocator.hpp +++ /dev/null @@ -1,84 +0,0 @@ - -// Copyright 2006-2009 Daniel James. -// Distributed under 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) - -#if !defined(BOOST_UNORDERED_TEST_MALLOC_ALLOCATOR_HEADER) -#define BOOST_UNORDERED_TEST_MALLOC_ALLOCATOR_HEADER - -#include -#include -#include -#include - -#if defined(BOOST_MSVC) -#pragma warning(push) -#pragma warning(disable:4100) // unreferenced formal parameter -#endif - -namespace test -{ - template - struct malloc_allocator - { - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; - typedef T* pointer; - typedef T const* const_pointer; - typedef T& reference; - typedef T const& const_reference; - typedef T value_type; - - template struct rebind { typedef malloc_allocator other; }; - - malloc_allocator() {} - template malloc_allocator(malloc_allocator const&) {} - malloc_allocator(malloc_allocator const&) {} - - pointer address(reference r) { return &r; } - const_pointer address(const_reference r) { return &r; } - - pointer allocate(size_type n) { - using namespace std; - T* ptr = static_cast(malloc(n * sizeof(T))); - if(!ptr) throw std::bad_alloc(); - return ptr; - } - - pointer allocate(size_type n, void const* u) { return allocate(n); } - - void deallocate(pointer p, size_type) { - using namespace std; - free(p); - } - void construct(pointer p, T const& t) { new(p) T(t); } - void destroy(pointer p) { p->~T(); } - - size_type max_size() const { - return (std::numeric_limits::max)(); - } - - bool operator==(malloc_allocator const&) const { return true; } - bool operator!=(malloc_allocator const&) const { return false; } - -#if BOOST_WORKAROUND(BOOST_MSVC, < 1300) - template void deallocate(T* p, size_type) { - using namespace std; - free(p); - } - char* _Charalloc(size_type n) { - using namespace std; - T* ptr = static_cast(malloc(n * sizeof(char))); - if(!ptr) throw std::bad_alloc(); - return (char*) ptr; - } -#endif - }; -} - -#if defined(BOOST_MSVC) -#pragma warning(pop) -#pragma warning(disable:4100) // unreferenced formal parameter -#endif - -#endif diff --git a/test/helpers/check_return_type.hpp b/test/helpers/check_return_type.hpp index bfcaab41..b73f9869 100644 --- a/test/helpers/check_return_type.hpp +++ b/test/helpers/check_return_type.hpp @@ -6,7 +6,7 @@ #if !defined(BOOST_UNORDERED_TEST_HELPERS_CHECK_RETURN_TYPE_HEADER) #define BOOST_UNORDERED_TEST_HELPERS_CHECK_RETURN_TYPE_HEADER -#include +#include #include #include @@ -18,19 +18,19 @@ namespace test template static void equals(T2) { - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); } template static void equals_ref(T2&) { - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); } template static void convertible(T2) { - BOOST_MPL_ASSERT((boost::is_convertible)); + BOOST_STATIC_ASSERT((boost::is_convertible::value)); } }; } diff --git a/test/helpers/count.hpp b/test/helpers/count.hpp index aec44fd9..b81b7e2b 100644 --- a/test/helpers/count.hpp +++ b/test/helpers/count.hpp @@ -52,30 +52,22 @@ namespace test { } }; - template - struct counted_object - { - static object_count count_; - - counted_object() { count_.construct(); } - counted_object(counted_object const&) { count_.construct(); } - ~counted_object() { count_.destruct(); } - }; - - template object_count counted_object::count_; - - struct globally_counted_object - : counted_object {}; - // This won't be a problem as I'm only using a single compile unit // in each test (this is actually require by the minimal test // framework). // // boostinspect:nounnamed namespace { - object_count& global_object_count = globally_counted_object::count_; + object_count global_object_count; } + struct counted_object + { + counted_object() { global_object_count.construct(); } + counted_object(counted_object const&) { global_object_count.construct(); } + ~counted_object() { global_object_count.destruct(); } + }; + struct check_instances { int instances; diff --git a/test/helpers/invariants.hpp b/test/helpers/invariants.hpp index 3caf1eca..abb8fb1e 100644 --- a/test/helpers/invariants.hpp +++ b/test/helpers/invariants.hpp @@ -13,7 +13,6 @@ #include #include "./metafunctions.hpp" #include "./helpers.hpp" -#include "./allocator.hpp" #if defined(BOOST_MSVC) #pragma warning(push) @@ -29,10 +28,7 @@ namespace test { BOOST_DEDUCED_TYPENAME X::key_equal eq = x1.key_eq(); typedef BOOST_DEDUCED_TYPENAME X::key_type key_type; - // Boost.Test was reporting memory leaks for std::set on g++-3.3. - // So I work around it by using malloc. - std::set, - test::malloc_allocator > found_; + std::set > found_; BOOST_DEDUCED_TYPENAME X::const_iterator it = x1.begin(), end = x1.end(); diff --git a/test/helpers/memory.hpp b/test/helpers/memory.hpp index af75328a..a30d7522 100644 --- a/test/helpers/memory.hpp +++ b/test/helpers/memory.hpp @@ -8,10 +8,8 @@ #include #include -#include #include -#include -#include +#include #include "../helpers/test.hpp" namespace test @@ -53,30 +51,10 @@ namespace test } }; - template - struct allocator_memory_type_gen { - typedef std::map type; - }; - -#if defined(BOOST_MPL_CFG_MSVC_ETI_BUG) - template <> - struct allocator_memory_type_gen { - typedef std::map - type; - }; -#endif - - template > struct memory_tracker { - typedef BOOST_DEDUCED_TYPENAME - ::boost::unordered::detail::rebind_wrap >::type - allocator_type; - - typedef BOOST_DEDUCED_TYPENAME - allocator_memory_type_gen::type - allocated_memory_type; + typedef std::map > + > allocated_memory_type; allocated_memory_type allocated_memory; unsigned int count_allocators; @@ -139,7 +117,7 @@ namespace test void track_deallocate(void* ptr, std::size_t n, std::size_t size, int tag, bool check_tag_ = true) { - BOOST_DEDUCED_TYPENAME allocated_memory_type::iterator pos = + allocated_memory_type::iterator pos = allocated_memory.find( memory_area(ptr, (char*) ptr + n * size)); if(pos == allocated_memory.end()) { @@ -177,33 +155,9 @@ namespace test // // boostinspect:nounnamed namespace { - test::detail::memory_tracker > tracker; + test::detail::memory_tracker tracker; } } - - template - struct bool_type { - enum { value = (Value ? true : false) }; - }; - - struct true_type { - enum { value = true }; - }; - - struct false_type { - enum { value = false }; - }; - - struct convert_from_anything - { - template - convert_from_anything(T const&) {} - }; - - int selected_count(convert_from_anything) - { - return 0; - } } #endif diff --git a/test/helpers/metafunctions.hpp b/test/helpers/metafunctions.hpp index 8c8afaaa..139fe0a2 100644 --- a/test/helpers/metafunctions.hpp +++ b/test/helpers/metafunctions.hpp @@ -8,72 +8,33 @@ #include #include -#include #include #include namespace test { - /* - struct unordered_set_type { char x[100]; }; - struct unordered_multiset_type { char x[200]; }; - struct unordered_map_type { char x[300]; }; - struct unordered_multimap_type { char x[400]; }; - - template - unordered_set_type container_type( - boost::unordered_set const*); - template - unordered_multiset_type container_type( - boost::unordered_multiset const*); - template - unordered_map_type container_type( - boost::unordered_map const*); - template - unordered_multimap_type container_type( - boost::unordered_multimap const*); - */ - template struct is_set : public boost::is_same< BOOST_DEDUCED_TYPENAME Container::key_type, BOOST_DEDUCED_TYPENAME Container::value_type> {}; - template - struct is_map - : public boost::mpl::not_ > {}; - - struct yes_type { char x[100]; }; - struct no_type { char x[200]; }; - - template - yes_type has_unique_key_impl( - boost::unordered_set const*); - template - no_type has_unique_key_impl( - boost::unordered_multiset const*); - template - yes_type has_unique_key_impl( - boost::unordered_map const*); - template - no_type has_unique_key_impl( - boost::unordered_multimap const*); - template struct has_unique_keys { - BOOST_STATIC_CONSTANT(bool, value = - sizeof(has_unique_key_impl((Container const*)0)) - == sizeof(yes_type)); + BOOST_STATIC_CONSTANT(bool, value = false); }; - template - struct has_equivalent_keys + template + struct has_unique_keys > { - BOOST_STATIC_CONSTANT(bool, value = - sizeof(has_unique_key_impl((Container const*)0)) - == sizeof(no_type)); + BOOST_STATIC_CONSTANT(bool, value = true); + }; + + template + struct has_unique_keys > + { + BOOST_STATIC_CONSTANT(bool, value = true); }; } diff --git a/test/helpers/random_values.hpp b/test/helpers/random_values.hpp index 85d22c7a..18e0eae9 100644 --- a/test/helpers/random_values.hpp +++ b/test/helpers/random_values.hpp @@ -8,7 +8,7 @@ #include "./list.hpp" #include -#include +#include #include "./generators.hpp" #include "./metafunctions.hpp" @@ -81,10 +81,12 @@ namespace test template struct unordered_generator_base - : public boost::mpl::if_< - test::is_set, + : public boost::detail::if_true< + test::is_set::value + >::BOOST_NESTED_TEMPLATE then< test::unordered_generator_set, - test::unordered_generator_map > + test::unordered_generator_map + > { }; diff --git a/test/helpers/strong.hpp b/test/helpers/strong.hpp index f525faf7..02fe267a 100644 --- a/test/helpers/strong.hpp +++ b/test/helpers/strong.hpp @@ -8,7 +8,6 @@ #include #include -#include "./metafunctions.hpp" #include "./equivalent.hpp" #include "./list.hpp" #include "./exception_test.hpp" diff --git a/test/helpers/tracker.hpp b/test/helpers/tracker.hpp index fdb30815..52d9fa45 100644 --- a/test/helpers/tracker.hpp +++ b/test/helpers/tracker.hpp @@ -13,9 +13,6 @@ #include #include #include -#include -#include -#include #include #include "../objects/fwd.hpp" #include "./metafunctions.hpp" @@ -25,21 +22,17 @@ namespace test { - template - struct equals_to_compare2 - : public boost::mpl::identity< - std::less > + template + struct equals_to_compare { + typedef std::less + type; }; - template - struct equals_to_compare - : public boost::mpl::eval_if< - boost::is_same, - boost::mpl::identity, - equals_to_compare2 - > + template <> + struct equals_to_compare { + typedef test::less type; }; template @@ -67,51 +60,40 @@ namespace test values2.begin(), test::equivalent)); } - template - struct ordered_set : public - boost::mpl::if_< - test::has_unique_keys, - std::set< - BOOST_DEDUCED_TYPENAME X::value_type, - BOOST_DEDUCED_TYPENAME equals_to_compare< - BOOST_DEDUCED_TYPENAME X::key_equal - >::type - >, - std::multiset< - BOOST_DEDUCED_TYPENAME X::value_type, - BOOST_DEDUCED_TYPENAME equals_to_compare< - BOOST_DEDUCED_TYPENAME X::key_equal - >::type - > - > {}; + template + struct ordered_base; - template - struct ordered_map : public - boost::mpl::if_< - test::has_unique_keys, - std::map< - BOOST_DEDUCED_TYPENAME X::key_type, - BOOST_DEDUCED_TYPENAME X::mapped_type, - BOOST_DEDUCED_TYPENAME equals_to_compare< - BOOST_DEDUCED_TYPENAME X::key_equal - >::type - >, - std::multimap< - BOOST_DEDUCED_TYPENAME X::key_type, - BOOST_DEDUCED_TYPENAME X::mapped_type, - BOOST_DEDUCED_TYPENAME equals_to_compare< - BOOST_DEDUCED_TYPENAME X::key_equal - >::type - > - > {}; + template + struct ordered_base > + { + typedef std::set::type> + type; + }; - template - struct ordered_base : public - boost::mpl::eval_if< - test::is_set, - test::ordered_set, - test::ordered_map - > {}; + template + struct ordered_base > + { + typedef std::multiset::type> + type; + }; + + template + struct ordered_base > + { + typedef std::map::type> + type; + }; + + template + struct ordered_base > + { + typedef std::multimap::type> + type; + }; template class ordered : public ordered_base::type diff --git a/test/objects/cxx11_allocator.hpp b/test/objects/cxx11_allocator.hpp index c24c57cc..bd707734 100644 --- a/test/objects/cxx11_allocator.hpp +++ b/test/objects/cxx11_allocator.hpp @@ -21,7 +21,8 @@ namespace test is_select_on_copy = 0, is_propagate_on_swap = 0, is_propagate_on_assign = 0, - is_propagate_on_move = 0 + is_propagate_on_move = 0, + cxx11_construct = 0 }; }; @@ -31,7 +32,8 @@ namespace test is_select_on_copy = 1, is_propagate_on_swap = 1, is_propagate_on_assign = 1, - is_propagate_on_move = 1 + is_propagate_on_move = 1, + cxx11_construct = 1 }; }; @@ -168,8 +170,8 @@ namespace test new(p) T(t); } -#if defined(BOOST_UNORDERED_VARIADIC_MOVE) - template void construct(T* p, Args&&... args) { +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) + template void construct(T* p, BOOST_FWD_REF(Args)... args) { detail::tracker.track_construct((void*) p, sizeof(T), tag_); new(p) T(boost::forward(args)...); } @@ -291,6 +293,20 @@ namespace test return x.tag_ == y.tag_; } + // Function to check how many times an allocator has been selected, + // return 0 for other allocators. + + struct convert_from_anything + { + template + convert_from_anything(T const&) {} + }; + + inline int selected_count(convert_from_anything) + { + return 0; + } + template int selected_count(cxx11_allocator const& x) { diff --git a/test/objects/exception.hpp b/test/objects/exception.hpp index 3b3c105e..9ff13005 100644 --- a/test/objects/exception.hpp +++ b/test/objects/exception.hpp @@ -13,21 +13,12 @@ #include #include #include "../helpers/fwd.hpp" -#include "../helpers/allocator.hpp" #include "../helpers/memory.hpp" namespace test { namespace exception { - namespace detail - { - namespace - { - test::detail::memory_tracker > tracker; - } - } - class object; class hash; class equal_to; @@ -259,7 +250,7 @@ namespace exception UNORDERED_SCOPE(allocator::allocator()) { UNORDERED_EPOINT("Mock allocator default constructor."); } - detail::tracker.allocator_ref(); + test::detail::tracker.allocator_ref(); } template allocator(allocator const& x) : tag_(x.tag_) @@ -267,7 +258,7 @@ namespace exception UNORDERED_SCOPE(allocator::allocator()) { UNORDERED_EPOINT("Mock allocator template copy constructor."); } - detail::tracker.allocator_ref(); + test::detail::tracker.allocator_ref(); } allocator(allocator const& x) : tag_(x.tag_) @@ -275,11 +266,11 @@ namespace exception UNORDERED_SCOPE(allocator::allocator()) { UNORDERED_EPOINT("Mock allocator copy constructor."); } - detail::tracker.allocator_ref(); + test::detail::tracker.allocator_ref(); } ~allocator() { - detail::tracker.allocator_unref(); + test::detail::tracker.allocator_unref(); } allocator& operator=(allocator const& x) { @@ -317,7 +308,7 @@ namespace exception ptr = (T*) malloc(n * sizeof(T)); if(!ptr) throw std::bad_alloc(); } - detail::tracker.track_allocate((void*) ptr, n, sizeof(T), tag_); + test::detail::tracker.track_allocate((void*) ptr, n, sizeof(T), tag_); return pointer(ptr); //return pointer(static_cast(::operator new(n * sizeof(T)))); @@ -333,7 +324,7 @@ namespace exception ptr = (T*) malloc(n * sizeof(T)); if(!ptr) throw std::bad_alloc(); } - detail::tracker.track_allocate((void*) ptr, n, sizeof(T), tag_); + test::detail::tracker.track_allocate((void*) ptr, n, sizeof(T), tag_); return pointer(ptr); //return pointer(static_cast(::operator new(n * sizeof(T)))); @@ -343,7 +334,7 @@ namespace exception { //::operator delete((void*) p); if(p) { - detail::tracker.track_deallocate((void*) p, n, sizeof(T), tag_); + test::detail::tracker.track_deallocate((void*) p, n, sizeof(T), tag_); using namespace std; free(p); } @@ -354,21 +345,21 @@ namespace exception UNORDERED_EPOINT("Mock allocator construct function."); new(p) T(t); } - detail::tracker.track_construct((void*) p, sizeof(T), tag_); + test::detail::tracker.track_construct((void*) p, sizeof(T), tag_); } -#if defined(BOOST_UNORDERED_VARIADIC_MOVE) - template void construct(T* p, Args&&... args) { - UNORDERED_SCOPE(allocator::construct(pointer, Args&&...)) { +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) + template void construct(T* p, BOOST_FWD_REF(Args)... args) { + UNORDERED_SCOPE(allocator::construct(pointer, BOOST_FWD_REF(Args)...)) { UNORDERED_EPOINT("Mock allocator construct function."); new(p) T(boost::forward(args)...); } - detail::tracker.track_construct((void*) p, sizeof(T), tag_); + test::detail::tracker.track_construct((void*) p, sizeof(T), tag_); } #endif void destroy(T* p) { - detail::tracker.track_destroy((void*) p, sizeof(T), tag_); + test::detail::tracker.track_destroy((void*) p, sizeof(T), tag_); p->~T(); } diff --git a/test/objects/minimal.hpp b/test/objects/minimal.hpp index f0b7bdcf..0d9ae8b2 100644 --- a/test/objects/minimal.hpp +++ b/test/objects/minimal.hpp @@ -367,8 +367,8 @@ namespace minimal void construct(T* p, T const& t) { new((void*)p) T(t); } -#if defined(BOOST_UNORDERED_VARIADIC_MOVE) - template void construct(T* p, Args&&... args) { +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) + template void construct(T* p, BOOST_FWD_REF(Args)... args) { new((void*)p) T(boost::forward(args)...); } #endif @@ -439,8 +439,8 @@ namespace minimal void construct(T* p, T const& t) { new((void*)p) T(t); } -#if defined(BOOST_UNORDERED_VARIADIC_MOVE) - template void construct(T* p, Args&&... args) { +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) + template void construct(T* p, BOOST_FWD_REF(Args)... args) { new((void*)p) T(boost::forward(args)...); } #endif diff --git a/test/objects/test.hpp b/test/objects/test.hpp index 54e97a51..62aae7aa 100644 --- a/test/objects/test.hpp +++ b/test/objects/test.hpp @@ -26,7 +26,7 @@ namespace test object generate(object const*); implicitly_convertible generate(implicitly_convertible const*); - class object : private globally_counted_object + class object : private counted_object { friend class hash; friend class equal_to; @@ -64,7 +64,7 @@ namespace test } }; - class implicitly_convertible : private globally_counted_object + class implicitly_convertible : private counted_object { int tag1_, tag2_; public: @@ -259,8 +259,8 @@ namespace test new(p) T(t); } -#if defined(BOOST_UNORDERED_VARIADIC_MOVE) - template void construct(T* p, Args&&... args) { +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) + template void construct(T* p, BOOST_FWD_REF(Args)... args) { detail::tracker.track_construct((void*) p, sizeof(T), tag_); new(p) T(boost::forward(args)...); } diff --git a/test/unordered/Jamfile.v2 b/test/unordered/Jamfile.v2 index 15095a10..77206493 100644 --- a/test/unordered/Jamfile.v2 +++ b/test/unordered/Jamfile.v2 @@ -15,9 +15,6 @@ project unordered-test/unordered darwin:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal" #gcc:_GLIBCXX_DEBUG #darwin:_GLIBCXX_DEBUG - #msvc:on - gcc:on - darwin:on ; test-suite unordered diff --git a/test/unordered/allocator_traits.cpp b/test/unordered/allocator_traits.cpp index 1921f61f..264c70d0 100644 --- a/test/unordered/allocator_traits.cpp +++ b/test/unordered/allocator_traits.cpp @@ -3,10 +3,10 @@ // Distributed under 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 +#include #include #include -#include +#include #include // Boilerplate @@ -91,15 +91,15 @@ void test_empty_allocator() typedef empty_allocator allocator; typedef boost::unordered::detail::allocator_traits traits; #if BOOST_UNORDERED_USE_ALLOCATOR_TRAITS == 1 - BOOST_MPL_ASSERT((boost::is_same::type>)); + BOOST_STATIC_ASSERT((boost::is_same::type>::value)); #else - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); #endif - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); BOOST_TEST(!traits::propagate_on_container_copy_assignment::value); BOOST_TEST(!traits::propagate_on_container_move_assignment::value); BOOST_TEST(!traits::propagate_on_container_swap::value); @@ -129,15 +129,15 @@ void test_allocator1() typedef allocator1 allocator; typedef boost::unordered::detail::allocator_traits traits; #if BOOST_UNORDERED_USE_ALLOCATOR_TRAITS == 1 - BOOST_MPL_ASSERT((boost::is_same::type>)); + BOOST_STATIC_ASSERT((boost::is_same::type>::value)); #else - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); #endif - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); BOOST_TEST(traits::propagate_on_container_copy_assignment::value); BOOST_TEST(traits::propagate_on_container_move_assignment::value); BOOST_TEST(traits::propagate_on_container_swap::value); @@ -174,11 +174,11 @@ void test_allocator2() { typedef allocator2 allocator; typedef boost::unordered::detail::allocator_traits traits; - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); BOOST_TEST(!traits::propagate_on_container_copy_assignment::value); BOOST_TEST(!traits::propagate_on_container_move_assignment::value); BOOST_TEST(!traits::propagate_on_container_swap::value); @@ -233,11 +233,11 @@ void test_allocator3() { typedef allocator3 allocator; typedef boost::unordered::detail::allocator_traits traits; - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same >)); - BOOST_MPL_ASSERT((boost::is_same >)); - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same >::value)); + BOOST_STATIC_ASSERT((boost::is_same >::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); BOOST_TEST(traits::propagate_on_container_copy_assignment::value); BOOST_TEST(!traits::propagate_on_container_move_assignment::value); BOOST_TEST(!traits::propagate_on_container_swap::value); diff --git a/test/unordered/compile_tests.hpp b/test/unordered/compile_tests.hpp index 255d841f..804b7ed4 100644 --- a/test/unordered/compile_tests.hpp +++ b/test/unordered/compile_tests.hpp @@ -16,8 +16,7 @@ #pragma warning(pop) #endif -#include -#include +#include #include #include #include @@ -55,42 +54,38 @@ void container_test(X& r, T const&) // value_type - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); boost::function_requires >(); // reference_type / const_reference_type - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); // iterator boost::function_requires >(); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_convertible)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_convertible::value)); // const_iterator boost::function_requires >(); - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); // difference_type - BOOST_MPL_ASSERT((boost::mpl::bool_< - std::numeric_limits::is_signed>)); - BOOST_MPL_ASSERT((boost::mpl::bool_< - std::numeric_limits::is_integer>)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT(std::numeric_limits::is_signed); + BOOST_STATIC_ASSERT(std::numeric_limits::is_integer); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); // size_type - BOOST_MPL_ASSERT_NOT((boost::mpl::bool_< - std::numeric_limits::is_signed>)); - BOOST_MPL_ASSERT((boost::mpl::bool_< - std::numeric_limits::is_integer>)); + BOOST_STATIC_ASSERT(!std::numeric_limits::is_signed); + BOOST_STATIC_ASSERT(std::numeric_limits::is_integer); // size_type can represent any non-negative value type of difference_type // I'm not sure about either of these tests... @@ -184,7 +179,7 @@ void unordered_set_test(X&, Key const&) typedef BOOST_DEDUCED_TYPENAME X::value_type value_type; typedef BOOST_DEDUCED_TYPENAME X::key_type key_type; - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); } template @@ -193,8 +188,8 @@ void unordered_map_test(X& r, Key const& k, T const& v) typedef BOOST_DEDUCED_TYPENAME X::value_type value_type; typedef BOOST_DEDUCED_TYPENAME X::key_type key_type; - BOOST_MPL_ASSERT(( - boost::is_same >)); + BOOST_STATIC_ASSERT(( + boost::is_same >::value)); r.insert(std::pair(k, v)); @@ -313,36 +308,36 @@ void unordered_test(X& x, Key& k, Hash& hf, Pred& eq) boost::iterator_reference::type const_local_iterator_reference; - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); //boost::function_requires >(); //boost::function_requires >(); - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); test::check_return_type::equals(hf(k)); - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); test::check_return_type::convertible(eq(k, k)); boost::function_requires >(); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); boost::function_requires< boost::InputIteratorConcept >(); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); X(10, hf, eq); X a(10, hf, eq); diff --git a/test/unordered/incomplete_test.cpp b/test/unordered/incomplete_test.cpp index 035dfb6f..4300a8e6 100644 --- a/test/unordered/incomplete_test.cpp +++ b/test/unordered/incomplete_test.cpp @@ -15,26 +15,25 @@ namespace x struct D { boost::unordered_map x; }; } -namespace test +namespace incomplete_test { // Declare, but don't define some types. struct value; struct hash; struct equals; - template - struct malloc_allocator; + template struct allocator; // Declare some instances typedef boost::unordered_map > > map; + allocator > > map; typedef boost::unordered_multimap > > multimap; + allocator > > multimap; typedef boost::unordered_set > set; + allocator > set; typedef boost::unordered_multiset > multiset; + allocator > multiset; // Now define the types which are stored as members, as they are needed for // declaring struct members. @@ -49,12 +48,17 @@ namespace test bool operator()(T const&, T const&) const { return true; } }; -} + // This is a dubious way to implement an allocator, but good enough + // for this test. + template + struct allocator : std::allocator { + allocator() {} -#include "../helpers/allocator.hpp" + template + allocator(const allocator& other) : + std::allocator(other) {} + }; -namespace test -{ // Declare some members of a structs. // // Incomplete hash, equals and allocator aren't here supported at the @@ -62,19 +66,19 @@ namespace test struct struct1 { boost::unordered_map > > x; + allocator > > x; }; struct struct2 { boost::unordered_multimap > > x; + allocator > > x; }; struct struct3 { boost::unordered_set > x; + allocator > x; }; struct struct4 { boost::unordered_multiset > x; + allocator > x; }; // Now define the value type. @@ -83,15 +87,15 @@ namespace test // Create some instances. - test::map m1; - test::multimap m2; - test::set s1; - test::multiset s2; + incomplete_test::map m1; + incomplete_test::multimap m2; + incomplete_test::set s1; + incomplete_test::multiset s2; - test::struct1 c1; - test::struct2 c2; - test::struct3 c3; - test::struct4 c4; + incomplete_test::struct1 c1; + incomplete_test::struct2 c2; + incomplete_test::struct3 c3; + incomplete_test::struct4 c4; // Now declare, but don't define, the operators required for comparing // elements. @@ -113,7 +117,7 @@ namespace test void use_types() { - test::value x; + incomplete_test::value x; m1[x] = x; m2.insert(std::make_pair(x, x)); s1.insert(x); @@ -145,5 +149,5 @@ int main() { // This could just be a compile test, but I like to be able to run these // things. It's probably irrational, but I find it reassuring. - test::use_types(); + incomplete_test::use_types(); } diff --git a/test/unordered/minimal_allocator.cpp b/test/unordered/minimal_allocator.cpp index 8f485bc4..26d1323a 100644 --- a/test/unordered/minimal_allocator.cpp +++ b/test/unordered/minimal_allocator.cpp @@ -3,10 +3,10 @@ // Distributed under 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 +#include #include #include -#include +#include #include "../objects/test.hpp" template @@ -41,22 +41,22 @@ void test_simple_allocator() typedef boost::unordered::detail::allocator_traits< SimpleAllocator > traits; - BOOST_MPL_ASSERT((boost::is_same >)); + BOOST_STATIC_ASSERT((boost::is_same >::value)); - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - //BOOST_MPL_ASSERT((boost::is_same)); - //BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + //BOOST_STATIC_ASSERT((boost::is_same::value)); + //BOOST_STATIC_ASSERT((boost::is_same::value)); - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); #if BOOST_UNORDERED_USE_ALLOCATOR_TRAITS == 1 - BOOST_MPL_ASSERT((boost::is_same::type>)); + BOOST_STATIC_ASSERT((boost::is_same::type>::value)); #else - BOOST_MPL_ASSERT((boost::is_same)); + BOOST_STATIC_ASSERT((boost::is_same::value)); #endif BOOST_TEST(!traits::propagate_on_container_copy_assignment::value); diff --git a/test/unordered/move_tests.cpp b/test/unordered/move_tests.cpp index 85159926..164eb88d 100644 --- a/test/unordered/move_tests.cpp +++ b/test/unordered/move_tests.cpp @@ -162,12 +162,12 @@ namespace move_tests #elif defined(BOOST_HAS_NRVO) BOOST_TEST( test::global_object_count.constructions - count.constructions <= - (test::is_map::value ? 50 : 25)); + (test::is_set::value ? 25 : 50)); BOOST_TEST(count.instances == test::global_object_count.instances); #else BOOST_TEST( test::global_object_count.constructions - count.constructions <= - (test::is_map::value ? 100 : 50)); + (test::is_set::value ? 50 : 100)); BOOST_TEST(count.instances == test::global_object_count.instances); #endif test::check_container(y, v); diff --git a/test/unordered/unnecessary_copy_tests.cpp b/test/unordered/unnecessary_copy_tests.cpp index c8efe28f..4e9e2c64 100644 --- a/test/unordered/unnecessary_copy_tests.cpp +++ b/test/unordered/unnecessary_copy_tests.cpp @@ -11,23 +11,6 @@ #include #include "../helpers/test.hpp" -#if defined(BOOST_UNORDERED_VARIADIC_MOVE) -# if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION) -# elif defined(__STD_RWCOMPILER_H__) || defined(_RWSTD_VER) -# elif defined(_LIBCPP_VERSION) -# define BOOST_UNORDERED_VARIADIC_MOVE -# elif defined(__GLIBCPP__) || defined(__GLIBCXX__) -# if defined(__GLIBCXX__) && __GLIBCXX__ >= 20090804 -# define BOOST_UNORDERED_VARIADIC_MOVE -# endif -# elif defined(__STL_CONFIG_H) -# elif defined(__MSL_CPP__) -# elif defined(__IBMCPP__) -# elif defined(MSIPL_COMPILE_H) -# elif (defined(_YVALS) && !defined(__IBMCPP__)) || defined(_CPPLIB_VER) -# endif -#endif - namespace unnecessary_copy_tests { struct count_copies @@ -262,7 +245,7 @@ namespace unnecessary_copy_tests // the existing element. reset(); x.emplace(); -#if !defined(BOOST_NO_RVALUE_REFERENCES) +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) // source_cost doesn't make much sense here, but it seems to fit. COPY_COUNT(1); MOVE_COUNT(source_cost); #else