diff --git a/include/boost/core/allocator_access.hpp b/include/boost/core/allocator_access.hpp index 7717ba0..567b448 100644 --- a/include/boost/core/allocator_access.hpp +++ b/include/boost/core/allocator_access.hpp @@ -430,30 +430,15 @@ allocator_allocate(A& a, typename allocator_size_type::type n, namespace detail { #if defined(BOOST_NO_CXX11_ALLOCATOR) -template -struct alloc_no { - char x, y; +template +struct alloc_has_construct { + BOOST_STATIC_CONSTEXPR bool value = false; }; -template -class alloc_has_construct { - template - static alloc_no - check(int); - - template - static alloc_no - check(int); - - template - static alloc_no - check(int); - - template - static char check(long); - -public: - static const bool value = sizeof(check(0)) > 1; +template +struct alloc_has_construct::type> { + BOOST_STATIC_CONSTEXPR bool value = true; }; #else template @@ -483,16 +468,14 @@ struct alloc_if { #if defined(BOOST_NO_CXX11_ALLOCATOR) template -inline typename detail::alloc_if::value>::type +inline typename detail::alloc_if::value>::type allocator_construct(A& a, T* p) { a.construct(p); } template -inline typename detail::alloc_if::value>::type +inline typename detail::alloc_if::value>::type allocator_construct(A&, T* p) { ::new((void*)p) T(); @@ -550,25 +533,15 @@ allocator_construct(A&, T* p, Args&&... args) namespace detail { #if defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct alloc_has_destroy { + BOOST_STATIC_CONSTEXPR bool value = false; +}; + template -class alloc_has_destroy { - template - static alloc_no - check(int); - - template - static alloc_no - check(int); - - template - static alloc_no - check(int); - - template - static char check(long); - -public: - static const bool value = sizeof(check(0)) > 1; +struct alloc_has_destroy::type> { + BOOST_STATIC_CONSTEXPR bool value = true; }; #else template @@ -605,6 +578,11 @@ allocator_destroy(A&, T* p) namespace detail { #if defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct alloc_no { + char x, y; +}; + template class alloc_has_max_size { template diff --git a/include/boost/core/noinit_adaptor.hpp b/include/boost/core/noinit_adaptor.hpp index 962b6e4..623e3ea 100644 --- a/include/boost/core/noinit_adaptor.hpp +++ b/include/boost/core/noinit_adaptor.hpp @@ -15,6 +15,8 @@ namespace boost { template struct noinit_adaptor : A { + typedef void _default_construct_destroy; + template struct rebind { typedef noinit_adaptor::type> other; diff --git a/test/allocator_construct_test.cpp b/test/allocator_construct_test.cpp index 30f2d0e..2bd1db2 100644 --- a/test/allocator_construct_test.cpp +++ b/test/allocator_construct_test.cpp @@ -26,16 +26,6 @@ struct A2 { }; #endif -template -struct A3 { - typedef T value_type; - A3() { } - template - void construct(U* p) { - ::new((void*)p) U(1); - } -}; - int main() { { @@ -52,11 +42,5 @@ int main() BOOST_TEST_EQ(i, 6); } #endif - { - A3 a; - int i = 0; - boost::allocator_construct(a, &i); - BOOST_TEST_EQ(i, 1); - } return boost::report_errors(); } diff --git a/test/allocator_destroy_n_test.cpp b/test/allocator_destroy_n_test.cpp index fc19469..381cd68 100644 --- a/test/allocator_destroy_n_test.cpp +++ b/test/allocator_destroy_n_test.cpp @@ -8,23 +8,59 @@ Distributed under the Boost Software License, Version 1.0. #include #include +struct S { + static int count; + S() { + ++count; + } + S(const S&) { + ++count; + } + ~S() { + --count; + } +}; + +int S::count = 0; + template -struct A { +struct A1 { typedef T value_type; - A() { } + A1() { } +}; + +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +template +struct A2 { + typedef T value_type; + A2() { } template void destroy(U* p) { *p = U(); } }; +#endif int main() { - A a; - int i[3] = { 5, 5, 5 }; - boost::allocator_destroy_n(a, &i[0], 3); - BOOST_TEST_EQ(i[0], 0); - BOOST_TEST_EQ(i[1], 0); - BOOST_TEST_EQ(i[2], 0); + { + A1 a; + S s[3]; + boost::allocator_destroy_n(a, &s[0], 3); + BOOST_TEST_EQ(S::count, 0); + ::new((void*)&s[0]) S(); + ::new((void*)&s[1]) S(); + ::new((void*)&s[2]) S(); + } +#if !defined(BOOST_NO_CXX11_ALLOCATOR) + { + A2 a; + int i[3] = { 5, 5, 5 }; + boost::allocator_destroy_n(a, &i[0], 3); + BOOST_TEST_EQ(i[0], 0); + BOOST_TEST_EQ(i[1], 0); + BOOST_TEST_EQ(i[2], 0); + } +#endif return boost::report_errors(); } diff --git a/test/allocator_destroy_test.cpp b/test/allocator_destroy_test.cpp index 04d794e..0b5b64e 100644 --- a/test/allocator_destroy_test.cpp +++ b/test/allocator_destroy_test.cpp @@ -29,6 +29,7 @@ struct A1 { A1() { } }; +#if !defined(BOOST_NO_CXX11_ALLOCATOR) template struct A2 { typedef T value_type; @@ -38,6 +39,7 @@ struct A2 { *p = U(); } }; +#endif int main() { @@ -48,11 +50,13 @@ int main() BOOST_TEST_EQ(S::count, 0); ::new((void*)&s) S(); } +#if !defined(BOOST_NO_CXX11_ALLOCATOR) { A2 a; int i = 5; boost::allocator_destroy(a, &i); BOOST_TEST_EQ(i, 0); } +#endif return boost::report_errors(); }