diff --git a/doc/allocator_access.qbk b/doc/allocator_access.qbk index 0bcc044..0d0eb34 100644 --- a/doc/allocator_access.qbk +++ b/doc/allocator_access.qbk @@ -21,9 +21,8 @@ templates to simplify allocator use. It provides the same functionality as the C++ standard library `std::allocator_traits` but with individual templates for each allocator feature. -This implementation supports C++03 and above. These facilities also simplify -existing libraries by avoiding having to check for `BOOST_NO_CXX11_ALLOCATOR` -and conditionally use `std::allocator_traits`. +These facilities also simplify existing libraries by avoiding having to check +for `BOOST_NO_CXX11_ALLOCATOR` and conditionally use `std::allocator_traits`. [endsect] @@ -142,14 +141,14 @@ allocator_pointer_t allocator_allocate(A& a, allocator_size_type_t n); template allocator_pointer_t allocator_allocate(A& a, allocator_size_type_t n, - allocator_const_void_pointer_t hint); + allocator_const_void_pointer_t h); template void allocator_deallocate(A& a, allocator_pointer_t p, allocator_size_type_t n); template -void allocator_construct(A& a, T*p, Args&&... args); +void allocator_construct(A& a, T* p, Args&&... args); template void allocator_destroy(A& a, T* p); diff --git a/include/boost/core/allocator_access.hpp b/include/boost/core/allocator_access.hpp index 2a5d3c3..bfe08f7 100644 --- a/include/boost/core/allocator_access.hpp +++ b/include/boost/core/allocator_access.hpp @@ -8,40 +8,53 @@ Distributed under the Boost Software License, Version 1.0. #ifndef BOOST_CORE_ALLOCATOR_ACCESS_HPP #define BOOST_CORE_ALLOCATOR_ACCESS_HPP +#include +#if !defined(BOOST_NO_CXX11_ALLOCATOR) #include +#if !defined(BOOST_MSVC) #include -#if defined(BOOST_DINKUMWARE_STDLIB) +#else #include #endif -#include -#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) #include #endif +#include #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) #include #endif -#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) || \ - defined(BOOST_MSVC) && BOOST_MSVC == 1800 -#define BOOST_CORE_ALLOCATOR_DETECTION +namespace boost { +namespace detail { + +#if defined(BOOST_NO_CXX11_ALLOCATOR) +struct alloc_false { + BOOST_STATIC_CONSTEXPR bool value = false; +}; +#else +template +struct alloc_void { + typedef void type; +}; #endif -namespace boost { +} /* detail */ template struct allocator_value_type { typedef typename A::value_type type; }; -namespace detail { - -template -struct alloc_void { - typedef void type; +#if defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct allocator_pointer { + typedef typename A::pointer type; }; - -} /* detail */ - +#elif defined(BOOST_MSVC) +template +struct allocator_pointer { + typedef typename std::allocator_traits::pointer type; +}; +#else template struct allocator_pointer { typedef typename A::value_type* type; @@ -52,7 +65,19 @@ struct allocator_pointer::type> { typedef typename A::pointer type; }; +#endif +#if defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct allocator_const_pointer { + typedef typename A::const_pointer type; +}; +#elif defined(BOOST_MSVC) +template +struct allocator_const_pointer { + typedef typename std::allocator_traits::const_pointer type; +}; +#else template struct allocator_const_pointer { typedef typename pointer_traits::type> { typedef typename A::const_pointer type; }; +#endif +#if defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct allocator_void_pointer { + typedef typename A::template rebind::other::pointer type; +}; +#else template struct allocator_void_pointer { typedef typename pointer_traits::type> { typedef typename A::void_pointer type; }; +#endif +#if defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct allocator_const_void_pointer { + typedef typename A::template rebind::other::const_pointer type; +}; +#else template struct allocator_const_void_pointer { typedef typename pointer_traits::type> { typedef typename A::const_void_pointer type; }; +#endif +#if defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct allocator_difference_type { + typedef typename A::difference_type type; +}; +#else template struct allocator_difference_type { typedef typename pointer_traits::type> { typedef typename A::difference_type type; }; +#endif -#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) +#if defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct allocator_size_type { + typedef typename A::size_type type; +}; +#else template struct allocator_size_type { typedef typename std::make_unsigned::type> { typedef typename A::size_type type; }; -#else +#endif + +#if defined(BOOST_NO_CXX11_ALLOCATOR) template -struct allocator_size_type { - typedef typename A::size_type type; +struct allocator_propagate_on_container_copy_assignment { + typedef detail::alloc_false type; }; -#endif - -namespace detail { - -#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) -typedef std::false_type alloc_false_type; #else -struct alloc_false_type { - BOOST_STATIC_CONSTEXPR bool value = false; -}; -#endif - -} /* detail */ - template struct allocator_propagate_on_container_copy_assignment { - typedef detail::alloc_false_type type; + typedef std::false_type type; }; template @@ -146,10 +187,17 @@ struct allocator_propagate_on_container_copy_assignment::type> { typedef typename A::propagate_on_container_copy_assignment type; }; +#endif +#if defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct allocator_propagate_on_container_move_assignment { + typedef detail::alloc_false type; +}; +#else template struct allocator_propagate_on_container_move_assignment { - typedef detail::alloc_false_type type; + typedef std::false_type type; }; template @@ -158,10 +206,17 @@ struct allocator_propagate_on_container_move_assignment::type> { typedef typename A::propagate_on_container_move_assignment type; }; +#endif +#if defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct allocator_propagate_on_container_swap { + typedef detail::alloc_false type; +}; +#else template struct allocator_propagate_on_container_swap { - typedef detail::alloc_false_type type; + typedef std::false_type type; }; template @@ -170,52 +225,46 @@ struct allocator_propagate_on_container_swap::type> { typedef typename A::propagate_on_container_swap type; }; +#endif -#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) -template +#if defined(BOOST_NO_CXX11_ALLOCATOR) +template struct allocator_is_always_equal { - typedef typename std::is_empty::type type; + typedef detail::alloc_false type; }; #else template struct allocator_is_always_equal { - typedef typename detail::alloc_false_type type; + typedef typename std::is_empty::type type; }; -#endif template struct allocator_is_always_equal::type> { typedef typename A::is_always_equal type; }; +#endif +#if defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct allocator_rebind { + typedef typename A::template rebind::other type; +}; +#elif defined(BOOST_MSVC) +template +struct allocator_rebind { + typedef typename std::allocator_traits::template rebind_alloc type; +}; +#else namespace detail { template struct alloc_to { }; -#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template class A, class T, class U, class... V> struct alloc_to, T> { typedef A type; }; -#else -template class A, class T, class U> -struct alloc_to, T> { - typedef A type; -}; - -template class A, class T, class U1, class U2> -struct alloc_to, T> { - typedef A type; -}; - -template class A, class T, class U1, class U2, - class U3> -struct alloc_to, T> { - typedef A type; -}; -#endif } /* detail */ @@ -229,6 +278,7 @@ struct allocator_rebind::other>::type> { typedef typename A::template rebind::other type; }; +#endif template inline typename allocator_pointer::type @@ -237,98 +287,6 @@ allocator_allocate(A& a, typename allocator_size_type::type n) return a.allocate(n); } -namespace detail { - -template -struct alloc_if { }; - -template -struct alloc_if { - typedef R type; -}; - -template -struct alloc_enable { - BOOST_STATIC_CONSTEXPR bool value = true; -}; - -#if defined(BOOST_DINKUMWARE_STDLIB) -template -struct alloc_enable > { - BOOST_STATIC_CONSTEXPR bool value = false; -}; -#endif - -#if defined(BOOST_CORE_ALLOCATOR_DETECTION) -template -T alloc_declval() BOOST_NOEXCEPT; -#endif - -#if defined(BOOST_MSVC) && BOOST_MSVC == 1800 -template -struct alloc_yes { - BOOST_STATIC_CONSTEXPR bool value = true; -}; - -struct alloc_no { - BOOST_STATIC_CONSTEXPR bool value = false; -}; -#endif - -template -struct alloc_has_allocate { - BOOST_STATIC_CONSTEXPR bool value = false; -}; - -#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) -template -struct alloc_has_allocate().allocate(alloc_declval(), - alloc_declval()), void())> { - BOOST_STATIC_CONSTEXPR bool value = true; -}; -#elif defined(BOOST_MSVC) && BOOST_MSVC == 1800 -template -struct alloc_has_allocate { -private: - template - static auto call(int, U& a) -> - alloc_yes(), - alloc_declval()))>; - - template - static alloc_no call(long, U&); - -public: - BOOST_STATIC_CONSTEXPR bool value = decltype(call(0, - alloc_declval()))::value; -}; -#endif - -} /* detail */ - -template -inline typename detail::alloc_if::value && - detail::alloc_has_allocate::type, - typename allocator_const_void_pointer::type>::value, - typename allocator_pointer::type>::type -allocator_allocate(A& a, typename allocator_size_type::type n, - typename allocator_const_void_pointer::type h) -{ - return a.allocate(n, h); -} - -template -inline typename detail::alloc_if::value || - !detail::alloc_has_allocate::type, - typename allocator_const_void_pointer::type>::value, - typename allocator_pointer::type>::type -allocator_allocate(A& a, typename allocator_size_type::type n, - typename allocator_const_void_pointer::type) -{ - return a.allocate(n); -} - template inline void allocator_deallocate(A& a, typename allocator_pointer::type p, @@ -337,191 +295,158 @@ allocator_deallocate(A& a, typename allocator_pointer::type p, a.deallocate(p, n); } -namespace detail { - -template -struct alloc_has_construct { - BOOST_STATIC_CONSTEXPR bool value = false; -}; - -#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) -template -struct alloc_has_construct().construct(alloc_declval()), void())> { - BOOST_STATIC_CONSTEXPR bool value = true; -}; -#elif defined(BOOST_MSVC) && BOOST_MSVC == 1800 -template -struct alloc_has_construct { -private: - template - static auto call(int, U& a) -> - alloc_yes()))>; - - template - static alloc_no call(long, U&); - -public: - BOOST_STATIC_CONSTEXPR bool value = decltype(call(0, - alloc_declval()))::value; -}; -#endif - -} /* detail */ - -template -inline typename detail::alloc_if::value && - detail::alloc_has_construct::value>::type -allocator_construct(A& a, T* p) +#if defined(BOOST_NO_CXX11_ALLOCATOR) +template +inline typename allocator_pointer::type +allocator_allocate(A& a, typename allocator_size_type::type n, + typename allocator_const_void_pointer::type h) { - a.construct(p); + return a.allocate(n, h); } - -template -inline typename detail::alloc_if::value || - !detail::alloc_has_construct::value>::type -allocator_construct(A&, T* p) +#elif defined(BOOST_MSVC) +template +inline typename allocator_pointer::type +allocator_allocate(A& a, typename allocator_size_type::type n, + typename allocator_const_void_pointer::type h) { - ::new((void*)p) T(); -} - -#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ - !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) -namespace detail { - -template -struct alloc_has_construct_args { - BOOST_STATIC_CONSTEXPR bool value = false; -}; - -#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) -template -struct alloc_has_construct_args().construct(alloc_declval(), alloc_declval()...), void()), - A, T, Args...> { - BOOST_STATIC_CONSTEXPR bool value = true; -}; -#elif defined(BOOST_MSVC) && BOOST_MSVC == 1800 -template -struct alloc_has_construct_args { -private: - template - static auto call(int, U& a) -> - alloc_yes(), - alloc_declval()...))>; - - template - static alloc_no call(long, U&); - -public: - BOOST_STATIC_CONSTEXPR bool value = decltype(call(0, - alloc_declval()))::value; -}; -#endif - -} /* detail */ - -template -inline typename detail::alloc_if::value && - detail::alloc_has_construct_args::value>::type -allocator_construct(A& a, T* p, V&& v, Args&&... args) -{ - a.construct(p, std::forward(v), std::forward(args)...); -} - -template -inline typename detail::alloc_if::value || - !detail::alloc_has_construct_args::value>::type -allocator_construct(A&, T* p, V&& v, Args&&... args) -{ - ::new((void*)p) T(std::forward(v), std::forward(args)...); + return std::allocator_traits::allocate(a, n, h); } #else namespace detail { template -struct alloc_has_construct_arg { +struct alloc_has_allocate { BOOST_STATIC_CONSTEXPR bool value = false; }; -#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) -template -struct alloc_has_construct_arg().construct(alloc_declval(), - alloc_declval()), void())> { +template +struct alloc_has_allocate().allocate(std::declval(), + std::declval()))>::type> { BOOST_STATIC_CONSTEXPR bool value = true; }; -#elif defined(BOOST_MSVC) && BOOST_MSVC == 1800 -template -struct alloc_has_construct_arg { -private: - template - static auto call(int, U& a) -> - alloc_yes(), - alloc_declval()))>; - - template - static alloc_no call(long, U&); - -public: - BOOST_STATIC_CONSTEXPR bool value = decltype(call(0, - alloc_declval()))::value; -}; -#endif } /* detail */ -#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) -template -inline typename detail::alloc_if::value && - detail::alloc_has_construct_arg::value>::type -allocator_construct(A& a, T* p, V&& v) +template +inline typename std::enable_if::type, + typename allocator_const_void_pointer::type>::value, + typename allocator_pointer::type>::type +allocator_allocate(A& a, typename allocator_size_type::type n, + typename allocator_const_void_pointer::type h) { - a.construct(p, std::forward(v)); + return a.allocate(n, h); } +template +inline typename std::enable_if::type, + typename allocator_const_void_pointer::type>::value, + typename allocator_pointer::type>::type +allocator_allocate(A& a, typename allocator_size_type::type n, + typename allocator_const_void_pointer::type) +{ + return a.allocate(n); +} +#endif + +#if defined(BOOST_NO_CXX11_ALLOCATOR) +template +inline void +allocator_construct(A&, T* p) +{ + ::new((void*)p) T(); +} + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +template +inline void +allocator_construct(A&, T* p, V&& v, Args&&... args) +{ + ::new((void*)p) T(std::forward(v), std::forward(args)...); +} +#else template -inline typename detail::alloc_if::value || - !detail::alloc_has_construct_arg::value>::type +inline void allocator_construct(A&, T* p, V&& v) { ::new((void*)p) T(std::forward(v)); } +#endif #else template -inline typename detail::alloc_if::value && - detail::alloc_has_construct_arg::value>::type -allocator_construct(A& a, T* p, const V& v) -{ - a.construct(p, v); -} - -template -inline typename detail::alloc_if::value || - !detail::alloc_has_construct_arg::value>::type +inline void allocator_construct(A&, T* p, const V& v) { ::new((void*)p) T(v); } template -inline typename detail::alloc_if::value && - detail::alloc_has_construct_arg::value>::type -allocator_construct(A& a, T* p, V& v) -{ - a.construct(p, v); -} - -template -inline typename detail::alloc_if::value || - !detail::alloc_has_construct_arg::value>::type +inline void allocator_construct(A&, T* p, V& v) { ::new((void*)p) T(v); } #endif +#elif defined(BOOST_MSVC) +template +inline void +allocator_construct(A& a, T* p, Args&&... args) +{ + std::allocator_traits::construct(a, p, std::forward(args)...); +} +#else +namespace detail { + +template +struct alloc_has_construct { + BOOST_STATIC_CONSTEXPR bool value = false; +}; + +template +struct alloc_has_construct().construct(std::declval(), std::declval()...))>::type, + A, T, Args...> { + BOOST_STATIC_CONSTEXPR bool value = true; +}; + +} /* detail */ + +template +inline typename std::enable_if::value>::type +allocator_construct(A& a, T* p, Args&&... args) +{ + a.construct(p, std::forward(args)...); +} + +template +inline typename std::enable_if::value>::type +allocator_construct(A&, T* p, Args&&... args) +{ + ::new((void*)p) T(std::forward(args)...); +} #endif +#if defined(BOOST_NO_CXX11_ALLOCATOR) +template +inline void +allocator_destroy(A&, T* p) +{ + p->~T(); + (void)p; +} +#elif defined(BOOST_MSVC) +template +inline void +allocator_destroy(A& a, T* p) +{ + std::allocator_traits::destroy(a, p); +} +#else namespace detail { template @@ -529,48 +454,46 @@ struct alloc_has_destroy { BOOST_STATIC_CONSTEXPR bool value = false; }; -#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) template struct alloc_has_destroy().destroy(alloc_declval()), void())> { + typename alloc_void().destroy(std::declval()))>::type> { BOOST_STATIC_CONSTEXPR bool value = true; }; -#elif defined(BOOST_MSVC) && BOOST_MSVC == 1800 -template -struct alloc_has_destroy { -private: - template - static auto call(int, U& a) -> - alloc_yes()))>; - - template - static alloc_no call(long, U&); - -public: - BOOST_STATIC_CONSTEXPR bool value = decltype(call(0, - alloc_declval()))::value; -}; -#endif } /* detail */ template -inline typename detail::alloc_if::value && - detail::alloc_has_destroy::value>::type +inline typename std::enable_if::value>::type allocator_destroy(A& a, T* p) { a.destroy(p); } template -inline typename detail::alloc_if::value || - !detail::alloc_has_destroy::value>::type +inline typename std::enable_if::value>::type allocator_destroy(A&, T* p) { p->~T(); (void)p; } +#endif +#if defined(BOOST_NO_CXX11_ALLOCATOR) +template +inline typename allocator_size_type::type +allocator_max_size(const A& a) +{ + return a.max_size(); +} +#elif defined(BOOST_MSVC) +template +inline typename allocator_size_type::type +allocator_max_size(const A& a) +{ + return std::allocator_traits::max_size(a); +} +#else namespace detail { template @@ -578,49 +501,48 @@ struct alloc_has_max_size { BOOST_STATIC_CONSTEXPR bool value = false; }; -#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) template struct alloc_has_max_size().max_size(), void())> { + typename alloc_void().max_size())>::type> { BOOST_STATIC_CONSTEXPR bool value = true; }; -#elif defined(BOOST_MSVC) && BOOST_MSVC == 1800 -template -struct alloc_has_max_size { -private: - template - static auto call(int, const U& a) -> alloc_yes; - - template - static alloc_no call(long, const U&); - -public: - BOOST_STATIC_CONSTEXPR bool value = decltype(call(0, - alloc_declval()))::value; -}; -#endif } /* detail */ template -inline typename detail::alloc_if::value && - detail::alloc_has_max_size::value, - typename allocator_size_type::type>::type +inline typename std::enable_if::value, + typename allocator_size_type::type>::type allocator_max_size(const A& a) { return a.max_size(); } template -inline typename detail::alloc_if::value || - !detail::alloc_has_max_size::value, - typename allocator_size_type::type>::type +inline typename std::enable_if::value, + typename allocator_size_type::type>::type allocator_max_size(const A&) { return (std::numeric_limits::type>::max)() / sizeof(typename A::value_type); } +#endif +#if defined(BOOST_NO_CXX11_ALLOCATOR) +template +inline A +allocator_select_on_container_copy_construction(const A& a) +{ + return a; +} +#elif defined(BOOST_MSVC) +template +inline A +allocator_select_on_container_copy_construction(const A& a) +{ + return std::allocator_traits::select_on_container_copy_construction(a); +} +#else namespace detail { template @@ -628,47 +550,29 @@ struct alloc_has_soccc { BOOST_STATIC_CONSTEXPR bool value = false; }; -#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) template struct alloc_has_soccc().select_on_container_copy_construction(), - void())> { + typename alloc_void().select_on_container_copy_construction())>::type> { BOOST_STATIC_CONSTEXPR bool value = true; }; -#elif defined(BOOST_MSVC) && BOOST_MSVC == 1800 -template -struct alloc_has_soccc { -private: - template - static auto call(int, const U& a) -> - alloc_yes; - - template - static alloc_no call(long, const U&); - -public: - BOOST_STATIC_CONSTEXPR bool value = decltype(call(0, - alloc_declval()))::value; -}; -#endif } /* detail */ template -inline typename detail::alloc_if::value && - detail::alloc_has_soccc::value, A>::type +inline typename std::enable_if::value, A>::type allocator_select_on_container_copy_construction(const A& a) { return a.select_on_container_copy_construction(); } template -inline typename detail::alloc_if::value || - !detail::alloc_has_soccc::value, A>::type +inline typename std::enable_if::value, A>::type allocator_select_on_container_copy_construction(const A& a) { return a; } +#endif #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) template diff --git a/test/alloc_construct_cxx11_test.cpp b/test/alloc_construct_cxx11_test.cpp index 9bdabb9..2075d7a 100644 --- a/test/alloc_construct_cxx11_test.cpp +++ b/test/alloc_construct_cxx11_test.cpp @@ -6,7 +6,7 @@ Distributed under the Boost Software License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) */ #include -#if defined(BOOST_CORE_ALLOCATOR_DETECTION) +#if !defined(BOOST_NO_CXX11_ALLOCATOR) #include #include diff --git a/test/allocator_allocate_hint_test.cpp b/test/allocator_allocate_hint_test.cpp index e5ca2f3..695e5d3 100644 --- a/test/allocator_allocate_hint_test.cpp +++ b/test/allocator_allocate_hint_test.cpp @@ -8,53 +8,51 @@ Distributed under the Boost Software License, Version 1.0. #include #include +template struct A1 { - typedef int* pointer; - typedef int size_type; - + typedef T value_type; + typedef std::size_t size_type; + typedef T* pointer; + typedef const T* const_pointer; + template + struct rebind { + typedef A1 other; + }; A1() : value() { } - - pointer allocate(size_type n) { + T* allocate(std::size_t n, const void*) { value = n; - return &value; + return 0; } - - size_type value; + std::size_t value; }; -#if defined(BOOST_CORE_ALLOCATOR_DETECTION) +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +template struct A2 { - typedef int* pointer; - typedef int size_type; - + typedef T value_type; A2() : value() { } - - pointer allocate(size_type n) { + T* allocate(std::size_t n) { value = n; - return &value; + return 0; } - - pointer allocate(size_type n, const void*) { - value = n + 1; - return &value; - } - - size_type value; + std::size_t value; }; #endif int main() { { - A1 a; - BOOST_TEST_EQ(*boost::allocator_allocate(a, 1, 0), 1); + A1 a; + BOOST_TEST_NOT(boost::allocator_allocate(a, 5, 0)); + BOOST_TEST_EQ(a.value, 5); } -#if defined(BOOST_CORE_ALLOCATOR_DETECTION) +#if !defined(BOOST_NO_CXX11_ALLOCATOR) { - A2 a; - BOOST_TEST_EQ(*boost::allocator_allocate(a, 1, 0), 2); + A2 a; + BOOST_TEST_NOT(boost::allocator_allocate(a, 5, 0)); + BOOST_TEST_EQ(a.value, 5); } #endif return boost::report_errors(); diff --git a/test/allocator_allocate_test.cpp b/test/allocator_allocate_test.cpp index 73ee06b..79122ee 100644 --- a/test/allocator_allocate_test.cpp +++ b/test/allocator_allocate_test.cpp @@ -8,24 +8,24 @@ Distributed under the Boost Software License, Version 1.0. #include #include +template struct A { - typedef int* pointer; - typedef int size_type; - + typedef T value_type; + typedef T* pointer; + typedef std::size_t size_type; A() : value() { } - - pointer allocate(size_type n) { + T* allocate(std::size_t n) { value = n; - return &value; + return 0; } - - size_type value; + std::size_t value; }; int main() { - A a; - BOOST_TEST_EQ(*boost::allocator_allocate(a, 5), 5); + A a; + BOOST_TEST_NOT(boost::allocator_allocate(a, 5)); + BOOST_TEST_EQ(a.value, 5); return boost::report_errors(); } diff --git a/test/allocator_const_pointer_test.cpp b/test/allocator_const_pointer_test.cpp index b8fc78d..16ae707 100644 --- a/test/allocator_const_pointer_test.cpp +++ b/test/allocator_const_pointer_test.cpp @@ -9,22 +9,26 @@ Distributed under the Boost Software License, Version 1.0. #include #include +template struct A1 { - typedef char value_type; - typedef int* pointer; + typedef T value_type; + typedef int* const_pointer; }; +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +template struct A2 { - typedef char value_type; - typedef int* pointer; - typedef const bool* const_pointer; + typedef T value_type; }; +#endif int main() { - BOOST_TEST_TRAIT_TRUE((boost::core::is_same::type>)); - BOOST_TEST_TRAIT_TRUE((boost::core::is_same::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same >::type>)); +#if !defined(BOOST_NO_CXX11_ALLOCATOR) + BOOST_TEST_TRAIT_TRUE((boost::core::is_same >::type>)); +#endif return boost::report_errors(); } diff --git a/test/allocator_const_void_pointer_test.cpp b/test/allocator_const_void_pointer_test.cpp index ed39feb..c07070d 100644 --- a/test/allocator_const_void_pointer_test.cpp +++ b/test/allocator_const_void_pointer_test.cpp @@ -9,20 +9,31 @@ Distributed under the Boost Software License, Version 1.0. #include #include +template struct A1 { - typedef int* pointer; + typedef T value_type; + typedef int* const_pointer; + typedef int* const_void_pointer; + template + struct rebind { + typedef A1 other; + }; }; +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +template struct A2 { - typedef int* pointer; - typedef const bool* const_void_pointer; + typedef T value_type; }; +#endif int main() { + BOOST_TEST_TRAIT_TRUE((boost::core::is_same >::type>)); +#if !defined(BOOST_NO_CXX11_ALLOCATOR) BOOST_TEST_TRAIT_TRUE((boost::core::is_same::type>)); - BOOST_TEST_TRAIT_TRUE((boost::core::is_same::type>)); + boost::allocator_const_void_pointer >::type>)); +#endif return boost::report_errors(); } diff --git a/test/allocator_construct_test.cpp b/test/allocator_construct_test.cpp index 8e7be0b..ded2278 100644 --- a/test/allocator_construct_test.cpp +++ b/test/allocator_construct_test.cpp @@ -6,43 +6,40 @@ Distributed under the Boost Software License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) */ #include -#include #include -struct S { - S(int v) - : value(v) { } - - int value; +template +struct A1 { + typedef T value_type; + A1() { } }; -struct A1 { }; - -#if defined(BOOST_CORE_ALLOCATOR_DETECTION) +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +template struct A2 { - void construct(S* p, int v) { - new(p) S(v + 1); + typedef T value_type; + A2() { } + template + void construct(U* p, const V& v) { + ::new((void*)p) U(v + 1); } }; #endif int main() { - boost::default_allocator d; { - S* p = d.allocate(1); - A1 a; - boost::allocator_construct(a, p, 1); - BOOST_TEST_EQ(p->value, 1); - d.deallocate(p, 1); + A1 a; + int i = 0; + boost::allocator_construct(a, &i, 5); + BOOST_TEST_EQ(i, 5); } -#if defined(BOOST_CORE_ALLOCATOR_DETECTION) +#if !defined(BOOST_NO_CXX11_ALLOCATOR) { - S* p = d.allocate(1); - A2 a; - boost::allocator_construct(a, p, 1); - BOOST_TEST_EQ(p->value, 2); - d.deallocate(p, 1); + A1 a; + int i = 0; + boost::allocator_construct(a, &i, 5); + BOOST_TEST_EQ(i, 6); } #endif return boost::report_errors(); diff --git a/test/allocator_deallocate_test.cpp b/test/allocator_deallocate_test.cpp index 83a4bda..9abab38 100644 --- a/test/allocator_deallocate_test.cpp +++ b/test/allocator_deallocate_test.cpp @@ -8,23 +8,22 @@ Distributed under the Boost Software License, Version 1.0. #include #include +template struct A { - typedef int* pointer; - typedef int size_type; - + typedef T value_type; + typedef T* pointer; + typedef std::size_t size_type; A() : value() { } - - void deallocate(pointer, size_type n) { + void deallocate(T*, std::size_t n) { value = n; } - - size_type value; + std::size_t value; }; int main() { - A a; + A a; boost::allocator_deallocate(a, 0, 5); BOOST_TEST_EQ(a.value, 5); return boost::report_errors(); diff --git a/test/allocator_destroy_test.cpp b/test/allocator_destroy_test.cpp index 5ecc6c0..9f2e0c0 100644 --- a/test/allocator_destroy_test.cpp +++ b/test/allocator_destroy_test.cpp @@ -6,20 +6,16 @@ Distributed under the Boost Software License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) */ #include -#include #include struct S { static int count; - S() { ++count; } - S(const S&) { ++count; } - ~S() { --count; } @@ -27,35 +23,39 @@ struct S { int S::count = 0; -struct A1 { }; +template +struct A1 { + typedef T value_type; + A1() { } +}; -#if defined(BOOST_CORE_ALLOCATOR_DETECTION) +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +template struct A2 { - void destroy(S*) { - ++S::count; + typedef T value_type; + A2() { } + template + void destroy(U* p) { + *p = U(); } }; #endif int main() { - boost::default_allocator d; { - S* p = d.allocate(1); - new(p) S; - A1 a; - boost::allocator_destroy(a, p); + A1 a; + S s; + boost::allocator_destroy(a, &s); BOOST_TEST_EQ(S::count, 0); - d.deallocate(p, 1); + ::new((void*)&s) S(); } -#if defined(BOOST_CORE_ALLOCATOR_DETECTION) +#if !defined(BOOST_NO_CXX11_ALLOCATOR) { - S* p = d.allocate(1); - new(p) S; - A2 a; - boost::allocator_destroy(a, p); - BOOST_TEST_EQ(S::count, 2); - d.deallocate(p, 1); + A1 a; + int i = 5; + boost::allocator_destroy(a, &i); + BOOST_TEST_EQ(i, 0); } #endif return boost::report_errors(); diff --git a/test/allocator_difference_type_test.cpp b/test/allocator_difference_type_test.cpp index d40ef46..24c373d 100644 --- a/test/allocator_difference_type_test.cpp +++ b/test/allocator_difference_type_test.cpp @@ -9,20 +9,26 @@ Distributed under the Boost Software License, Version 1.0. #include #include +template struct A1 { - typedef char* pointer; + typedef T value_type; + typedef short difference_type; }; +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +template struct A2 { - typedef char* pointer; - typedef int difference_type; + typedef T value_type; }; +#endif int main() { + BOOST_TEST_TRAIT_TRUE((boost::core::is_same >::type>)); +#if !defined(BOOST_NO_CXX11_ALLOCATOR) BOOST_TEST_TRAIT_TRUE((boost::core::is_same::type>)); - BOOST_TEST_TRAIT_TRUE((boost::core::is_same::type>)); + boost::allocator_difference_type >::type>)); +#endif return boost::report_errors(); } diff --git a/test/allocator_is_always_equal_test.cpp b/test/allocator_is_always_equal_test.cpp index aef2f60..c0d8bf2 100644 --- a/test/allocator_is_always_equal_test.cpp +++ b/test/allocator_is_always_equal_test.cpp @@ -9,28 +9,39 @@ Distributed under the Boost Software License, Version 1.0. #include #include +template struct A1 { + typedef T value_type; int value; }; +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +template struct A2 { - struct is_always_equal { - BOOST_STATIC_CONSTEXPR bool value = true; - }; - - int value; + typedef T value_type; }; -#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) -struct A3 { }; +template +struct A3 { + typedef T value_type; + typedef std::false_type is_always_equal; +}; + +template +struct A4 { + typedef T value_type; + typedef std::true_type is_always_equal; + int value; +}; #endif int main() { - BOOST_TEST_TRAIT_FALSE((boost::allocator_is_always_equal::type)); - BOOST_TEST_TRAIT_TRUE((boost::allocator_is_always_equal::type)); -#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) - BOOST_TEST_TRAIT_TRUE((boost::allocator_is_always_equal::type)); -#endif + BOOST_TEST_TRAIT_FALSE((boost::allocator_is_always_equal >::type)); + #if !defined(BOOST_NO_CXX11_ALLOCATOR) + BOOST_TEST_TRAIT_TRUE((boost::allocator_is_always_equal >::type)); + BOOST_TEST_TRAIT_FALSE((boost::allocator_is_always_equal >::type)); + BOOST_TEST_TRAIT_TRUE((boost::allocator_is_always_equal >::type)); + #endif return boost::report_errors(); } diff --git a/test/allocator_max_size_test.cpp b/test/allocator_max_size_test.cpp index 0ad609a..7da57d6 100644 --- a/test/allocator_max_size_test.cpp +++ b/test/allocator_max_size_test.cpp @@ -7,29 +7,33 @@ Distributed under the Boost Software License, Version 1.0. */ #include #include +#include +template struct A1 { - typedef long value_type; + typedef T value_type; typedef short size_type; -}; - -#if defined(BOOST_CORE_ALLOCATOR_DETECTION) -struct A2 { - typedef long value_type; - typedef short size_type; - - size_type max_size() const { + A1() { } + short max_size() const { return 1; } }; + +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct A2 { + typedef T value_type; + typedef short size_type; + A2() { } +}; #endif int main() { - BOOST_TEST_EQ(boost::allocator_max_size(A1()), - std::numeric_limits::max() / sizeof(A1::value_type)); -#if defined(BOOST_CORE_ALLOCATOR_DETECTION) - BOOST_TEST_EQ(boost::allocator_max_size(A2()), 1); + BOOST_TEST_EQ(boost::allocator_max_size(A1()), 1); +#if !defined(BOOST_NO_CXX11_ALLOCATOR) + BOOST_TEST_LE(boost::allocator_max_size(A2()), + (std::numeric_limits::max)()); #endif return boost::report_errors(); } diff --git a/test/allocator_pocca_test.cpp b/test/allocator_pocca_test.cpp index 80e9e75..2318652 100644 --- a/test/allocator_pocca_test.cpp +++ b/test/allocator_pocca_test.cpp @@ -9,19 +9,26 @@ Distributed under the Boost Software License, Version 1.0. #include #include -struct A1 { }; - -struct A2 { - struct propagate_on_container_copy_assignment { - BOOST_STATIC_CONSTEXPR bool value = true; - }; +template +struct A1 { + typedef T value_type; }; +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct A2 { + typedef T value_type; + typedef std::true_type propagate_on_container_copy_assignment; +}; +#endif + int main() { BOOST_TEST_TRAIT_FALSE((boost:: - allocator_propagate_on_container_copy_assignment::type)); + allocator_propagate_on_container_copy_assignment >::type)); +#if !defined(BOOST_NO_CXX11_ALLOCATOR) BOOST_TEST_TRAIT_TRUE((boost:: - allocator_propagate_on_container_copy_assignment::type)); + allocator_propagate_on_container_copy_assignment >::type)); +#endif return boost::report_errors(); } diff --git a/test/allocator_pocma_test.cpp b/test/allocator_pocma_test.cpp index c8d1a45..a971c02 100644 --- a/test/allocator_pocma_test.cpp +++ b/test/allocator_pocma_test.cpp @@ -9,19 +9,26 @@ Distributed under the Boost Software License, Version 1.0. #include #include -struct A1 { }; - -struct A2 { - struct propagate_on_container_move_assignment { - BOOST_STATIC_CONSTEXPR bool value = true; - }; +template +struct A1 { + typedef T value_type; }; +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct A2 { + typedef T value_type; + typedef std::true_type propagate_on_container_move_assignment; +}; +#endif + int main() { BOOST_TEST_TRAIT_FALSE((boost:: - allocator_propagate_on_container_move_assignment::type)); + allocator_propagate_on_container_move_assignment >::type)); +#if !defined(BOOST_NO_CXX11_ALLOCATOR) BOOST_TEST_TRAIT_TRUE((boost:: - allocator_propagate_on_container_move_assignment::type)); + allocator_propagate_on_container_move_assignment >::type)); +#endif return boost::report_errors(); } diff --git a/test/allocator_pocs_test.cpp b/test/allocator_pocs_test.cpp index 3fa94c1..1a8e6e2 100644 --- a/test/allocator_pocs_test.cpp +++ b/test/allocator_pocs_test.cpp @@ -9,19 +9,26 @@ Distributed under the Boost Software License, Version 1.0. #include #include -struct A1 { }; - -struct A2 { - struct propagate_on_container_swap { - BOOST_STATIC_CONSTEXPR bool value = true; - }; +template +struct A1 { + typedef T value_type; }; +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct A2 { + typedef T value_type; + typedef std::true_type propagate_on_container_swap; +}; +#endif + int main() { BOOST_TEST_TRAIT_FALSE((boost:: - allocator_propagate_on_container_swap::type)); + allocator_propagate_on_container_swap >::type)); +#if !defined(BOOST_NO_CXX11_ALLOCATOR) BOOST_TEST_TRAIT_TRUE((boost:: - allocator_propagate_on_container_swap::type)); + allocator_propagate_on_container_swap >::type)); +#endif return boost::report_errors(); } diff --git a/test/allocator_pointer_test.cpp b/test/allocator_pointer_test.cpp index 95eade2..6359492 100644 --- a/test/allocator_pointer_test.cpp +++ b/test/allocator_pointer_test.cpp @@ -9,20 +9,26 @@ Distributed under the Boost Software License, Version 1.0. #include #include +template struct A1 { - typedef char value_type; -}; - -struct A2 { - typedef char value_type; + typedef T value_type; typedef int* pointer; }; +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct A2 { + typedef T value_type; +}; +#endif + int main() { - BOOST_TEST_TRAIT_TRUE((boost::core::is_same::type>)); BOOST_TEST_TRAIT_TRUE((boost::core::is_same::type>)); + boost::allocator_pointer >::type>)); +#if !defined(BOOST_NO_CXX11_ALLOCATOR) + BOOST_TEST_TRAIT_TRUE((boost::core::is_same >::type>)); +#endif return boost::report_errors(); } diff --git a/test/allocator_rebind_test.cpp b/test/allocator_rebind_test.cpp index 5e4030f..4e35da4 100644 --- a/test/allocator_rebind_test.cpp +++ b/test/allocator_rebind_test.cpp @@ -9,22 +9,29 @@ Distributed under the Boost Software License, Version 1.0. #include #include -template -struct A1 { }; - -template -struct A2 { - template +template +struct A1 { + typedef T value_type; + template struct rebind { - typedef A1 other; + typedef A1 other; }; }; +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct A2 { + typedef T value_type; +}; +#endif + int main() { - BOOST_TEST_TRAIT_TRUE((boost::core::is_same, - boost::allocator_rebind, bool>::type>)); - BOOST_TEST_TRAIT_TRUE((boost::core::is_same, - boost::allocator_rebind, bool>::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same, + boost::allocator_rebind, bool>::type>)); +#if !defined(BOOST_NO_CXX11_ALLOCATOR) + BOOST_TEST_TRAIT_TRUE((boost::core::is_same, + boost::allocator_rebind, int>::type>)); +#endif return boost::report_errors(); } diff --git a/test/allocator_size_type_test.cpp b/test/allocator_size_type_test.cpp index bdc8dc5..4b3cf36 100644 --- a/test/allocator_size_type_test.cpp +++ b/test/allocator_size_type_test.cpp @@ -9,26 +9,26 @@ Distributed under the Boost Software License, Version 1.0. #include #include -#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) +template struct A1 { - typedef long difference_type; + typedef T value_type; + typedef int size_type; }; -#else -struct A1 { - typedef unsigned long size_type; + +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct A2 { + typedef T value_type; }; #endif -struct A2 { - typedef long difference_type; - typedef unsigned short size_type; -}; - int main() { - BOOST_TEST_TRAIT_TRUE((boost::core::is_same::type>)); - BOOST_TEST_TRAIT_TRUE((boost::core::is_same::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same >::type>)); +#if !defined(BOOST_NO_CXX11_ALLOCATOR) + BOOST_TEST_TRAIT_TRUE((boost::core::is_same >::type>)); +#endif return boost::report_errors(); } diff --git a/test/allocator_soccc_test.cpp b/test/allocator_soccc_test.cpp index d361549..2d25fbd 100644 --- a/test/allocator_soccc_test.cpp +++ b/test/allocator_soccc_test.cpp @@ -8,33 +8,34 @@ Distributed under the Boost Software License, Version 1.0. #include #include +template struct A1 { - A1(int v) - : value(v) { } - + typedef T value_type; + A1(int n) + : value(n) { } int value; }; -#if defined(BOOST_CORE_ALLOCATOR_DETECTION) +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +template struct A2 { - A2(int v) - : value(v) { } - + typedef T value_type; + A2(int n) + : value(n) { } A2 select_on_container_copy_construction() const { return A2(value + 1); } - int value; }; #endif int main() { - BOOST_TEST_EQ(1, - boost::allocator_select_on_container_copy_construction(A1(1)).value); -#if defined(BOOST_CORE_ALLOCATOR_DETECTION) - BOOST_TEST_EQ(2, - boost::allocator_select_on_container_copy_construction(A2(1)).value); + BOOST_TEST_EQ(1, boost:: + allocator_select_on_container_copy_construction(A1(1)).value); +#if !defined(BOOST_NO_CXX11_ALLOCATOR) + BOOST_TEST_EQ(2, boost:: + allocator_select_on_container_copy_construction(A2(1)).value); #endif return boost::report_errors(); } diff --git a/test/allocator_value_type_test.cpp b/test/allocator_value_type_test.cpp index ddd5601..575222c 100644 --- a/test/allocator_value_type_test.cpp +++ b/test/allocator_value_type_test.cpp @@ -9,13 +9,14 @@ Distributed under the Boost Software License, Version 1.0. #include #include +template struct A { - typedef int value_type; + typedef T value_type; }; int main() { BOOST_TEST_TRAIT_TRUE((boost::core::is_same::type>)); + boost::allocator_value_type >::type>)); return boost::report_errors(); } diff --git a/test/allocator_void_pointer_test.cpp b/test/allocator_void_pointer_test.cpp index 2ec053b..c5c08c1 100644 --- a/test/allocator_void_pointer_test.cpp +++ b/test/allocator_void_pointer_test.cpp @@ -9,20 +9,31 @@ Distributed under the Boost Software License, Version 1.0. #include #include +template struct A1 { + typedef T value_type; typedef int* pointer; + typedef int* void_pointer; + template + struct rebind { + typedef A1 other; + }; }; +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +template struct A2 { - typedef int* pointer; - typedef bool* void_pointer; + typedef T value_type; }; +#endif int main() { + BOOST_TEST_TRAIT_TRUE((boost::core::is_same >::type>)); +#if !defined(BOOST_NO_CXX11_ALLOCATOR) BOOST_TEST_TRAIT_TRUE((boost::core::is_same::type>)); - BOOST_TEST_TRAIT_TRUE((boost::core::is_same::type>)); + boost::allocator_void_pointer >::type>)); +#endif return boost::report_errors(); }