diff --git a/include/boost/unordered/detail/implementation.hpp b/include/boost/unordered/detail/implementation.hpp index 480aef32..f2980285 100644 --- a/include/boost/unordered/detail/implementation.hpp +++ b/include/boost/unordered/detail/implementation.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -47,7 +48,6 @@ #include #include - #if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) #include #endif @@ -124,14 +124,22 @@ // Other configuration macros // -#if BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT || \ - (!defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(__SUNPRO_CC)) -#define BOOST_UNORDERED_HAS_STD_TUPLE 1 +#if defined(BOOST_UNORDERED_TUPLE_ARGS) +#elif defined(__SUNPRO_CC) +#define BOOST_UNORDERED_TUPLE_ARGS 0 +#elif !defined(BOOST_NO_CXX11_HDR_TUPLE) +#define BOOST_UNORDERED_TUPLE_ARGS 10 +#elif BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT +#if defined(BOOST_MSVC) && defined(_VARIADIC_MAX) +#define BOOST_UNORDERED_TUPLE_ARGS _VARIADIC_MAX #else -#define BOOST_UNORDERED_HAS_STD_TUPLE 0 +#define BOOST_UNORDERED_TUPLE_ARGS 5 +#endif +#else +#define BOOST_UNORDERED_TUPLE_ARGS 0 #endif -#if BOOST_UNORDERED_HAS_STD_TUPLE +#if BOOST_UNORDERED_TUPLE_ARGS #include #endif @@ -1317,97 +1325,103 @@ inline void construct_value(T* address, BOOST_FWD_REF(A0) a0) // // Used to emulate piecewise construction. -#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#if !defined(__SUNPRO_CC) -#define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(n, namespace_) \ - template \ - void construct_from_tuple(Alloc&, 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_) \ +#define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(z, n, namespace_) \ template \ void construct_from_tuple(Alloc&, T* ptr, \ - namespace_ tuple const& x) \ + 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) +#define BOOST_UNORDERED_GET_TUPLE_ARG(z, n, namespace_) namespace_::get(x) -#elif !defined(__SUNPRO_CC) +// construct_from_tuple for boost::tuple -#define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(n, namespace_) \ - template \ - void construct_from_tuple(Alloc&, T* ptr, namespace_ tuple<>) \ - { \ - new ((void*)ptr) T(); \ - } \ - \ - BOOST_PP_REPEAT_FROM_TO( \ - 1, n, BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL, namespace_) +template +void construct_from_tuple(Alloc&, T* ptr, boost::tuple<>) +{ + new ((void*)ptr) T(); +} -#define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE_IMPL(z, n, namespace_) \ - template \ - void construct_from_tuple(Alloc&, T* ptr, \ - namespace_ tuple const& x) \ - { \ - new ((void*)ptr) T( \ - BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_GET_TUPLE_ARG, namespace_)); \ - } +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 1, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 2, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 3, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 4, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 5, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 6, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 7, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 8, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 9, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 10, boost) -#define BOOST_UNORDERED_GET_TUPLE_ARG(z, n, namespace_) namespace_ get(x) +// construct_from_tuple for std::tuple -#else +#if !BOOST_UNORDERED_CXX11_CONSTRUCTION && BOOST_UNORDERED_TUPLE_ARGS + +template +void construct_from_tuple(Alloc&, T* ptr, std::tuple<>) +{ + new ((void*)ptr) T(); +} + +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 1, std) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 2, std) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 3, std) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 4, std) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 5, std) + +#if BOOST_UNORDERED_TUPLE_ARGS >= 6 +BOOST_PP_REPEAT_FROM_TO(6, BOOST_PP_INC(BOOST_UNORDERED_TUPLE_ARGS), + BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE, std) +#endif + +#endif + +#undef BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE +#undef BOOST_UNORDERED_GET_TUPLE_ARG + +#else // __SUNPRO_CC template struct length { }; -#define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(n, namespace_) \ - template \ - void construct_from_tuple_impl(boost::unordered::detail::func::length<0>, \ - Alloc&, 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_) \ +#define BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(z, n, namespace_) \ template \ void construct_from_tuple_impl(boost::unordered::detail::func::length, \ Alloc&, T* ptr, \ - namespace_ tuple const& x) \ + 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) +#define BOOST_UNORDERED_GET_TUPLE_ARG(z, n, namespace_) namespace_::get(x) -#endif +// construct_from_tuple for boost::tuple -BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(10, boost::) +template +void construct_from_tuple_impl( + boost::unordered::detail::func::length<0>, Alloc&, T* ptr, boost::tuple<>) +{ + new ((void*)ptr) T(); +} -#if !BOOST_UNORDERED_CXX11_CONSTRUCTION && BOOST_UNORDERED_HAS_STD_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) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 1, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 2, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 3, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 4, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 5, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 6, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 7, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 8, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 9, boost) +BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(1, 10, boost) template void construct_from_tuple(Alloc& alloc, T* ptr, Tuple const& x) @@ -1417,6 +1431,9 @@ void construct_from_tuple(Alloc& alloc, T* ptr, Tuple const& x) alloc, ptr, x); } +#undef BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE +#undef BOOST_UNORDERED_GET_TUPLE_ARG + #endif //////////////////////////////////////////////////////////////////////////// @@ -3548,7 +3565,7 @@ template struct map_extractor BOOST_UNORDERED_KEY_FROM_TUPLE(boost::) -#if BOOST_UNORDERED_HAS_STD_TUPLE +#if BOOST_UNORDERED_TUPLE_ARGS BOOST_UNORDERED_KEY_FROM_TUPLE(std::) #endif }; diff --git a/test/unordered/unnecessary_copy_tests.cpp b/test/unordered/unnecessary_copy_tests.cpp index 7aea3111..9618778b 100644 --- a/test/unordered/unnecessary_copy_tests.cpp +++ b/test/unordered/unnecessary_copy_tests.cpp @@ -501,7 +501,7 @@ UNORDERED_AUTO_TEST(unnecessary_copy_emplace_map_test) COPY_COUNT(0); MOVE_COUNT(0); -#if BOOST_UNORDERED_HAS_STD_TUPLE +#if BOOST_UNORDERED_TUPLE_ARGS reset(); x.emplace(boost::unordered::piecewise_construct,