diff --git a/include/boost/unordered/detail/fwd.hpp b/include/boost/unordered/detail/fwd.hpp index 74419062..6a842042 100644 --- a/include/boost/unordered/detail/fwd.hpp +++ b/include/boost/unordered/detail/fwd.hpp @@ -15,21 +15,21 @@ // Already defined. #elif defined(BOOST_LIBSTDCXX11) // https://github.com/gcc-mirror/gcc/blob/gcc-4_6-branch/libstdc++-v3/include/bits/stl_pair.h#L70 -# if BOOST_LIBSTDCXX_VERSION > 40600 -# define BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT 1 -# endif +#if BOOST_LIBSTDCXX_VERSION > 40600 +#define BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT 1 +#endif #elif defined(_LIBCPP_VERSION) // https://github.com/llvm-mirror/libcxx/blob/release_30/include/utility#L206 -# if LIBCPP_VERSION >= 3000 -# define BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT 1 -# endif +#if LIBCPP_VERSION >= 3000 +#define BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT 1 +#endif #elif defined(BOOST_MSVC) // Apparently C++11 standard supported in Visual Studio 2012 // https://msdn.microsoft.com/en-us/library/hh567368.aspx#stl // 2012 = VC+11 = BOOST_MSVC 1700 Hopefully! -# if BOOST_MSVC >= 1700 -# define BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT 1 -# endif +#if BOOST_MSVC >= 1700 +#define BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT 1 +#endif #endif #if !defined(BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT) @@ -40,16 +40,16 @@ #include #endif -namespace boost -{ -namespace unordered -{ +namespace boost { +namespace unordered { #if BOOST_UNORDERED_HAVE_PIECEWISE_CONSTRUCT - using std::piecewise_construct_t; - using std::piecewise_construct; +using std::piecewise_construct_t; +using std::piecewise_construct; #else - struct piecewise_construct_t {}; - const piecewise_construct_t piecewise_construct = piecewise_construct_t(); +struct piecewise_construct_t +{ +}; +const piecewise_construct_t piecewise_construct = piecewise_construct_t(); #endif } } diff --git a/include/boost/unordered/detail/implementation.hpp b/include/boost/unordered/detail/implementation.hpp index ec5d129e..78850bba 100644 --- a/include/boost/unordered/detail/implementation.hpp +++ b/include/boost/unordered/detail/implementation.hpp @@ -10,84 +10,89 @@ #pragma once #endif -#include -#include -#include -#include -#include +#include +#include #include +#include +#include +#include #include -#include -#include -#include -#include #include #include #include -#include #include +#include #include -#include +#include +#include +#include +#include +#include +#include #include #include #include -#include +#include +#include +#include #include -#include -#include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include +#include #include +#include #if !defined(BOOST_NO_CXX11_HDR_TUPLE) #include #endif -namespace boost { namespace unordered { namespace detail { +namespace boost { +namespace unordered { +namespace detail { - static const float minimum_max_load_factor = 1e-3f; - static const std::size_t default_bucket_count = 11; - struct move_tag {}; - struct empty_emplace {}; +static const float minimum_max_load_factor = 1e-3f; +static const std::size_t default_bucket_count = 11; +struct move_tag +{ +}; +struct empty_emplace +{ +}; - namespace func { - template - inline void ignore_unused_variable_warning(T const&) {} - } +namespace func { +template inline void ignore_unused_variable_warning(T const&) {} +} - //////////////////////////////////////////////////////////////////////////// - // iterator SFINAE +//////////////////////////////////////////////////////////////////////////// +// iterator SFINAE - template - struct is_forward : - boost::is_convertible< - typename boost::iterator_traversal::type, - boost::forward_traversal_tag> - {}; +template +struct is_forward + : boost::is_convertible::type, + boost::forward_traversal_tag> +{ +}; - template - struct enable_if_forward : - boost::enable_if_c< - boost::unordered::detail::is_forward::value, - ReturnType> - {}; +template +struct enable_if_forward + : boost::enable_if_c::value, + ReturnType> +{ +}; - template - struct disable_if_forward : - boost::disable_if_c< - boost::unordered::detail::is_forward::value, - ReturnType> - {}; +template +struct disable_if_forward + : boost::disable_if_c::value, + ReturnType> +{ +}; - //////////////////////////////////////////////////////////////////////////// - // primes +//////////////////////////////////////////////////////////////////////////// +// primes // clang-format off #define BOOST_UNORDERED_PRIMES \ @@ -100,242 +105,268 @@ namespace boost { namespace unordered { namespace detail { (1610612741ul)(3221225473ul)(4294967291ul) // clang-format on - template struct prime_list_template - { - static std::size_t const value[]; +template struct prime_list_template +{ + static std::size_t const value[]; #if !defined(SUNPRO_CC) - static std::ptrdiff_t const length; + static std::ptrdiff_t const length; #else - static std::ptrdiff_t const length - = BOOST_PP_SEQ_SIZE(BOOST_UNORDERED_PRIMES); + static std::ptrdiff_t const length = + BOOST_PP_SEQ_SIZE(BOOST_UNORDERED_PRIMES); #endif - }; +}; - template - std::size_t const prime_list_template::value[] = { - BOOST_PP_SEQ_ENUM(BOOST_UNORDERED_PRIMES) - }; +template +std::size_t const prime_list_template::value[] = { + BOOST_PP_SEQ_ENUM(BOOST_UNORDERED_PRIMES)}; #if !defined(SUNPRO_CC) - template - std::ptrdiff_t const prime_list_template::length - = BOOST_PP_SEQ_SIZE(BOOST_UNORDERED_PRIMES); +template +std::ptrdiff_t const prime_list_template::length = BOOST_PP_SEQ_SIZE( + BOOST_UNORDERED_PRIMES); #endif #undef BOOST_UNORDERED_PRIMES - typedef prime_list_template prime_list; +typedef prime_list_template prime_list; - // no throw - inline std::size_t next_prime(std::size_t num) { - std::size_t const* const prime_list_begin = prime_list::value; - std::size_t const* const prime_list_end = prime_list_begin + - prime_list::length; - std::size_t const* bound = - std::lower_bound(prime_list_begin, prime_list_end, num); - if(bound == prime_list_end) - bound--; - return *bound; +// no throw +inline std::size_t next_prime(std::size_t num) +{ + std::size_t const* const prime_list_begin = prime_list::value; + std::size_t const* const prime_list_end = + prime_list_begin + prime_list::length; + std::size_t const* bound = + std::lower_bound(prime_list_begin, prime_list_end, num); + if (bound == prime_list_end) + bound--; + return *bound; +} + +// no throw +inline std::size_t prev_prime(std::size_t num) +{ + std::size_t const* const prime_list_begin = prime_list::value; + std::size_t const* const prime_list_end = + prime_list_begin + prime_list::length; + std::size_t const* bound = + std::upper_bound(prime_list_begin, prime_list_end, num); + if (bound != prime_list_begin) + bound--; + return *bound; +} + +//////////////////////////////////////////////////////////////////////////// +// insert_size/initial_size + +template +inline std::size_t insert_size(I i, I j, + typename boost::unordered::detail::enable_if_forward::type = 0) +{ + return static_cast(std::distance(i, j)); +} + +template +inline std::size_t insert_size(I, I, + typename boost::unordered::detail::disable_if_forward::type = 0) +{ + return 1; +} + +template +inline std::size_t initial_size(I i, I j, + std::size_t num_buckets = boost::unordered::detail::default_bucket_count) +{ + // TODO: Why +1? + return (std::max)( + boost::unordered::detail::insert_size(i, j) + 1, num_buckets); +} + +//////////////////////////////////////////////////////////////////////////// +// compressed + +template struct compressed_base : private T +{ + compressed_base(T const& x) : T(x) {} + compressed_base(T& x, move_tag) : T(boost::move(x)) {} + + T& get() { return *this; } + T const& get() const { return *this; } +}; + +template struct uncompressed_base +{ + uncompressed_base(T const& x) : value_(x) {} + uncompressed_base(T& x, move_tag) : value_(boost::move(x)) {} + + T& get() { return value_; } + T const& get() const { return value_; } + private: + T value_; +}; + +template +struct generate_base + : boost::detail::if_true::value>::BOOST_NESTED_TEMPLATE + then, + boost::unordered::detail::uncompressed_base > +{ +}; + +template +struct compressed + : private boost::unordered::detail::generate_base::type, + private boost::unordered::detail::generate_base::type +{ + typedef typename generate_base::type base1; + typedef typename generate_base::type base2; + + typedef T1 first_type; + typedef T2 second_type; + + first_type& first() { return static_cast(this)->get(); } + + first_type const& first() const + { + return static_cast(this)->get(); } - // no throw - inline std::size_t prev_prime(std::size_t num) { - std::size_t const* const prime_list_begin = prime_list::value; - std::size_t const* const prime_list_end = prime_list_begin + - prime_list::length; - std::size_t const* bound = - std::upper_bound(prime_list_begin,prime_list_end, num); - if(bound != prime_list_begin) - bound--; - return *bound; + second_type& second() { return static_cast(this)->get(); } + + second_type const& second() const + { + return static_cast(this)->get(); } - //////////////////////////////////////////////////////////////////////////// - // insert_size/initial_size - - template - inline std::size_t insert_size(I i, I j, typename - boost::unordered::detail::enable_if_forward::type = 0) + template + compressed(First const& x1, Second const& x2) : base1(x1), base2(x2) { - return static_cast(std::distance(i, j)); } - template - inline std::size_t insert_size(I, I, typename - boost::unordered::detail::disable_if_forward::type = 0) + compressed(compressed const& x) : base1(x.first()), base2(x.second()) {} + + compressed(compressed& x, move_tag m) + : base1(x.first(), m), base2(x.second(), m) { - return 1; } - template - inline std::size_t initial_size(I i, I j, - std::size_t num_buckets = - boost::unordered::detail::default_bucket_count) + void assign(compressed const& x) { - // TODO: Why +1? - return (std::max)( - boost::unordered::detail::insert_size(i, j) + 1, - num_buckets); + first() = x.first(); + second() = x.second(); } - //////////////////////////////////////////////////////////////////////////// - // compressed - - template - struct compressed_base : private T + void move_assign(compressed& x) { - compressed_base(T const& x) : T(x) {} - compressed_base(T& x, move_tag) : T(boost::move(x)) {} + first() = boost::move(x.first()); + second() = boost::move(x.second()); + } - T& get() { return *this; } - T const& get() const { return *this; } - }; - - template - struct uncompressed_base + void swap(compressed& x) { - uncompressed_base(T const& x) : value_(x) {} - uncompressed_base(T& x, move_tag) : value_(boost::move(x)) {} + boost::swap(first(), x.first()); + boost::swap(second(), x.second()); + } - T& get() { return value_; } - T const& get() const { return value_; } - private: - T value_; - }; - - template - struct generate_base - : boost::detail::if_true< - boost::is_empty::value - >:: BOOST_NESTED_TEMPLATE then< - boost::unordered::detail::compressed_base, - boost::unordered::detail::uncompressed_base - > - {}; - - template - struct compressed - : private boost::unordered::detail::generate_base::type, - private boost::unordered::detail::generate_base::type - { - typedef typename generate_base::type base1; - typedef typename generate_base::type base2; - - typedef T1 first_type; - typedef T2 second_type; - - first_type& first() { - return static_cast(this)->get(); - } - - first_type const& first() const { - return static_cast(this)->get(); - } - - second_type& second() { - return static_cast(this)->get(); - } - - second_type const& second() const { - return static_cast(this)->get(); - } - - template - compressed(First const& x1, Second const& x2) - : base1(x1), base2(x2) {} - - compressed(compressed const& x) - : base1(x.first()), base2(x.second()) {} - - compressed(compressed& x, move_tag m) - : base1(x.first(), m), base2(x.second(), m) {} - - void assign(compressed const& x) - { - first() = x.first(); - second() = x.second(); - } - - void move_assign(compressed& x) - { - first() = boost::move(x.first()); - second() = boost::move(x.second()); - } - - void swap(compressed& x) - { - boost::swap(first(), x.first()); - boost::swap(second(), x.second()); - } - - private: - // Prevent assignment just to make use of assign or - // move_assign explicit. - compressed& operator=(compressed const&); - }; -}}} + private: + // Prevent assignment just to make use of assign or + // move_assign explicit. + compressed& operator=(compressed const&); +}; +} +} +} #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. +#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 // Maximum number of arguments supported by emplace + 1. #define BOOST_UNORDERED_EMPLACE_LIMIT 11 -namespace boost { namespace unordered { namespace detail { +namespace boost { +namespace unordered { +namespace detail { - //////////////////////////////////////////////////////////////////////////// - // Bits and pieces for implementing traits +//////////////////////////////////////////////////////////////////////////// +// 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(); +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; +typedef choice1::type yes_type; +typedef choice2::type no_type; - struct private_type - { - private_type const &operator,(int) const; - }; +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&); +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&); - }; +struct convert_from_anything +{ + template convert_from_anything(T const&); +}; - namespace func { - // This is a bit nasty, when constructing the individual members - // of a std::pair, need to cast away 'const'. For modern compilers, - // should be able to use std::piecewise_construct instead. - template T* const_cast_pointer(T* x) { return x; } - template T* const_cast_pointer(T const* x) { - return const_cast(x); - } - } +namespace func { +// This is a bit nasty, when constructing the individual members +// of a std::pair, need to cast away 'const'. For modern compilers, +// should be able to use std::piecewise_construct instead. +template T* const_cast_pointer(T* x) { return x; } +template T* const_cast_pointer(T const* x) +{ + return const_cast(x); +} +} - //////////////////////////////////////////////////////////////////////////// - // emplace_args - // - // Either forwarding variadic arguments, or storing the arguments in - // emplace_args##n +//////////////////////////////////////////////////////////////////////////// +// emplace_args +// +// Either forwarding variadic arguments, or storing the arguments in +// emplace_args##n #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) @@ -359,21 +390,20 @@ namespace boost { namespace unordered { namespace detail { #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) -#define BOOST_UNORDERED_EARGS_MEMBER(z, n, _) \ - typedef BOOST_FWD_REF(BOOST_PP_CAT(A, n)) BOOST_PP_CAT(Arg, n); \ +#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); #else -#define BOOST_UNORDERED_EARGS_MEMBER(z, n, _) \ - typedef typename boost::add_lvalue_reference::type \ - BOOST_PP_CAT(Arg, n); \ +#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); #endif -template -struct emplace_args1 +template struct emplace_args1 { BOOST_UNORDERED_EARGS_MEMBER(1, 0, _) @@ -381,15 +411,13 @@ struct emplace_args1 }; template -inline emplace_args1 create_emplace_args( - BOOST_FWD_REF(A0) b0) +inline emplace_args1 create_emplace_args(BOOST_FWD_REF(A0) b0) { emplace_args1 e(b0); return e; } -template -struct emplace_args2 +template struct emplace_args2 { BOOST_UNORDERED_EARGS_MEMBER(1, 0, _) BOOST_UNORDERED_EARGS_MEMBER(1, 1, _) @@ -399,15 +427,13 @@ struct emplace_args2 template inline emplace_args2 create_emplace_args( - BOOST_FWD_REF(A0) b0, - BOOST_FWD_REF(A1) b1) + BOOST_FWD_REF(A0) b0, BOOST_FWD_REF(A1) b1) { emplace_args2 e(b0, b1); return e; } -template -struct emplace_args3 +template struct emplace_args3 { BOOST_UNORDERED_EARGS_MEMBER(1, 0, _) BOOST_UNORDERED_EARGS_MEMBER(1, 1, _) @@ -418,58 +444,53 @@ struct emplace_args3 template inline emplace_args3 create_emplace_args( - BOOST_FWD_REF(A0) b0, - BOOST_FWD_REF(A1) b1, - BOOST_FWD_REF(A2) b2) + BOOST_FWD_REF(A0) b0, BOOST_FWD_REF(A1) b1, BOOST_FWD_REF(A2) b2) { emplace_args3 e(b0, b1, b2); return e; } -#define BOOST_UNORDERED_FWD_PARAM(z, n, a) \ +#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_CALL_FORWARD(z, i, a) \ + boost::forward(BOOST_PP_CAT(a, i)) -#define BOOST_UNORDERED_EARGS_INIT(z, n, _) \ -BOOST_PP_CAT(a, n)(BOOST_PP_CAT(b, n)) +#define BOOST_UNORDERED_EARGS_INIT(z, n, _) \ + BOOST_PP_CAT(a, n)(BOOST_PP_CAT(b, n)) -#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_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) \ + create_emplace_args( \ + BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, b)) \ + { \ + BOOST_PP_CAT(emplace_args, n) e( \ + BOOST_PP_ENUM_PARAMS_Z(z, n, b)); \ + return e; \ } -BOOST_PP_REPEAT_FROM_TO(4, BOOST_UNORDERED_EMPLACE_LIMIT, BOOST_UNORDERED_EARGS, - _) +BOOST_PP_REPEAT_FROM_TO( + 4, BOOST_UNORDERED_EMPLACE_LIMIT, BOOST_UNORDERED_EARGS, _) #undef BOOST_UNORDERED_DEFINE_EMPLACE_ARGS #undef BOOST_UNORDERED_EARGS_MEMBER #undef BOOST_UNORDERED_EARGS_INIT #endif - -}}} +} +} +} //////////////////////////////////////////////////////////////////////////////// // @@ -480,19 +501,19 @@ BOOST_PP_REPEAT_FROM_TO(4, BOOST_UNORDERED_EMPLACE_LIMIT, BOOST_UNORDERED_EARGS, // 2 = boost::container::allocator_traits #if !defined(BOOST_UNORDERED_USE_ALLOCATOR_TRAITS) -# if !defined(BOOST_NO_CXX11_ALLOCATOR) -# define BOOST_UNORDERED_USE_ALLOCATOR_TRAITS 1 -# elif defined(BOOST_MSVC) -# if BOOST_MSVC < 1400 - // Use container's allocator_traits for older versions of Visual - // C++ as I don't test with them. -# define BOOST_UNORDERED_USE_ALLOCATOR_TRAITS 2 -# endif -# endif +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +#define BOOST_UNORDERED_USE_ALLOCATOR_TRAITS 1 +#elif defined(BOOST_MSVC) +#if BOOST_MSVC < 1400 +// Use container's allocator_traits for older versions of Visual +// C++ as I don't test with them. +#define BOOST_UNORDERED_USE_ALLOCATOR_TRAITS 2 +#endif +#endif #endif #if !defined(BOOST_UNORDERED_USE_ALLOCATOR_TRAITS) -# define BOOST_UNORDERED_USE_ALLOCATOR_TRAITS 0 +#define BOOST_UNORDERED_USE_ALLOCATOR_TRAITS 0 #endif //////////////////////////////////////////////////////////////////////////////// @@ -501,134 +522,156 @@ BOOST_PP_REPEAT_FROM_TO(4, BOOST_UNORDERED_EMPLACE_LIMIT, BOOST_UNORDERED_EARGS, // they're always defined. #if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) -# include +#include #endif -namespace boost { namespace unordered { namespace detail { +namespace boost { +namespace unordered { +namespace detail { - //////////////////////////////////////////////////////////////////////////// - // Integral_constrant, true_type, false_type - // - // Uses the standard versions if available. +//////////////////////////////////////////////////////////////////////////// +// Integral_constrant, true_type, false_type +// +// Uses the standard versions if available. #if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) - using std::integral_constant; - using std::true_type; - using std::false_type; +using std::integral_constant; +using std::true_type; +using std::false_type; #else - template - struct integral_constant { enum { value = Value }; }; +template struct integral_constant +{ + enum + { + value = Value + }; +}; - typedef boost::unordered::detail::integral_constant true_type; - typedef boost::unordered::detail::integral_constant false_type; +typedef boost::unordered::detail::integral_constant true_type; +typedef boost::unordered::detail::integral_constant false_type; #endif - //////////////////////////////////////////////////////////////////////////// - // Explicitly call a destructor +//////////////////////////////////////////////////////////////////////////// +// Explicitly call a destructor #if defined(BOOST_MSVC) #pragma warning(push) -#pragma warning(disable:4100) // unreferenced formal parameter +#pragma warning(disable : 4100) // unreferenced formal parameter #endif - namespace func { - template - inline void destroy(T* x) { - x->~T(); - } - } +namespace func { +template inline void destroy(T* x) { x->~T(); } +} #if defined(BOOST_MSVC) #pragma warning(pop) #endif - //////////////////////////////////////////////////////////////////////////// - // Expression test mechanism - // - // When SFINAE expressions are available, define - // BOOST_UNORDERED_HAS_FUNCTION which can check if a function call is - // supported by a class, otherwise define BOOST_UNORDERED_HAS_MEMBER which - // can detect if a class has the specified member, but not that it has the - // correct type, this is good enough for a passable impression of - // allocator_traits. +//////////////////////////////////////////////////////////////////////////// +// Expression test mechanism +// +// When SFINAE expressions are available, define +// BOOST_UNORDERED_HAS_FUNCTION which can check if a function call is +// supported by a class, otherwise define BOOST_UNORDERED_HAS_MEMBER which +// can detect if a class has the specified member, but not that it has the +// correct type, this is good enough for a passable impression of +// allocator_traits. #if !defined(BOOST_NO_SFINAE_EXPR) - template struct expr_test; - template struct expr_test : T {}; +template struct expr_test; +template struct expr_test : T +{ +}; -# define BOOST_UNORDERED_CHECK_EXPRESSION(count, result, expression) \ - template \ - static typename boost::unordered::detail::expr_test< \ - BOOST_PP_CAT(choice, result), \ - sizeof(for_expr_test(( \ - (expression), \ - 0)))>::type test( \ - BOOST_PP_CAT(choice, count)) +#define BOOST_UNORDERED_CHECK_EXPRESSION(count, result, expression) \ + template \ + static typename boost::unordered::detail::expr_test::type \ + test(BOOST_PP_CAT(choice, count)) -# define BOOST_UNORDERED_DEFAULT_EXPRESSION(count, result) \ - template \ - static BOOST_PP_CAT(choice, result)::type test( \ - BOOST_PP_CAT(choice, count)) +#define BOOST_UNORDERED_DEFAULT_EXPRESSION(count, result) \ + template \ + static BOOST_PP_CAT(choice, result)::type test( \ + BOOST_PP_CAT(choice, count)) -# define BOOST_UNORDERED_HAS_FUNCTION(name, thing, args, _) \ - struct BOOST_PP_CAT(has_, name) \ - { \ - template static char for_expr_test(U const&); \ - BOOST_UNORDERED_CHECK_EXPRESSION(1, 1, \ - boost::unordered::detail::make< thing >().name args); \ - BOOST_UNORDERED_DEFAULT_EXPRESSION(2, 2); \ - \ - enum { value = sizeof(test(choose())) == sizeof(choice1::type) };\ +#define BOOST_UNORDERED_HAS_FUNCTION(name, thing, args, _) \ + struct BOOST_PP_CAT(has_, name) \ + { \ + template static char for_expr_test(U const&); \ + BOOST_UNORDERED_CHECK_EXPRESSION( \ + 1, 1, boost::unordered::detail::make().name args); \ + BOOST_UNORDERED_DEFAULT_EXPRESSION(2, 2); \ + \ + enum \ + { \ + value = sizeof(test(choose())) == sizeof(choice1::type) \ + }; \ } #else - template struct identity { typedef T type; }; +template struct identity +{ + typedef T type; +}; -# define BOOST_UNORDERED_CHECK_MEMBER(count, result, name, member) \ - \ - typedef typename boost::unordered::detail::identity::type \ - BOOST_PP_CAT(check, count); \ - \ - template \ - struct BOOST_PP_CAT(test, count) { \ - typedef BOOST_PP_CAT(choice, result) type; \ - }; \ - \ - template static typename \ - BOOST_PP_CAT(test, count)<&U::name>::type \ - test(BOOST_PP_CAT(choice, count)) +#define BOOST_UNORDERED_CHECK_MEMBER(count, result, name, member) \ + \ + typedef typename boost::unordered::detail::identity::type \ + BOOST_PP_CAT(check, count); \ + \ + template struct BOOST_PP_CAT(test, count) \ + { \ + typedef BOOST_PP_CAT(choice, result) type; \ + }; \ + \ + template \ + static typename BOOST_PP_CAT(test, count)<&U::name>::type test( \ + BOOST_PP_CAT(choice, count)) -# define BOOST_UNORDERED_DEFAULT_MEMBER(count, result) \ - template static BOOST_PP_CAT(choice, result)::type \ - test(BOOST_PP_CAT(choice, count)) +#define BOOST_UNORDERED_DEFAULT_MEMBER(count, result) \ + template \ + static BOOST_PP_CAT(choice, result)::type test( \ + BOOST_PP_CAT(choice, count)) -# define BOOST_UNORDERED_HAS_MEMBER(name) \ - struct BOOST_PP_CAT(has_, name) \ - { \ - struct impl { \ - struct base_mixin { int name; }; \ - struct base : public T, public base_mixin {}; \ - \ - BOOST_UNORDERED_CHECK_MEMBER(1, 1, name, int base_mixin::*); \ - BOOST_UNORDERED_DEFAULT_MEMBER(2, 2); \ - \ - enum { value = sizeof(choice2::type) == \ - sizeof(test(choose())) \ - }; \ - }; \ - \ - enum { value = impl::value }; \ +#define BOOST_UNORDERED_HAS_MEMBER(name) \ + struct BOOST_PP_CAT(has_, name) \ + { \ + struct impl \ + { \ + struct base_mixin \ + { \ + int name; \ + }; \ + struct base : public T, public base_mixin \ + { \ + }; \ + \ + BOOST_UNORDERED_CHECK_MEMBER(1, 1, name, int base_mixin::*); \ + BOOST_UNORDERED_DEFAULT_MEMBER(2, 2); \ + \ + enum \ + { \ + value = sizeof(choice2::type) == sizeof(test(choose())) \ + }; \ + }; \ + \ + enum \ + { \ + value = impl::value \ + }; \ } #endif - -}}} +} +} +} //////////////////////////////////////////////////////////////////////////////// // @@ -638,445 +681,434 @@ namespace boost { namespace unordered { namespace detail { #if BOOST_UNORDERED_USE_ALLOCATOR_TRAITS == 0 -# include -# include -# include -# if defined(BOOST_NO_SFINAE_EXPR) -# include -# endif +#include +#include +#include +#if defined(BOOST_NO_SFINAE_EXPR) +#include +#endif -# if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \ - !defined(BOOST_NO_SFINAE_EXPR) -# define BOOST_UNORDERED_DETAIL_FULL_CONSTRUCT 1 -# else -# define BOOST_UNORDERED_DETAIL_FULL_CONSTRUCT 0 -# endif +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \ + !defined(BOOST_NO_SFINAE_EXPR) +#define BOOST_UNORDERED_DETAIL_FULL_CONSTRUCT 1 +#else +#define BOOST_UNORDERED_DETAIL_FULL_CONSTRUCT 0 +#endif -namespace boost { namespace unordered { namespace detail { +namespace boost { +namespace unordered { +namespace detail { - template - struct rebind_alloc; +template struct rebind_alloc; #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) - template class Alloc, - typename U, typename T, typename... Args> - struct rebind_alloc, T> - { - typedef Alloc type; - }; +template