diff --git a/include/boost/smart_ptr/detail/array_allocator.hpp b/include/boost/smart_ptr/detail/array_allocator.hpp index f085523..68170e9 100644 --- a/include/boost/smart_ptr/detail/array_allocator.hpp +++ b/include/boost/smart_ptr/detail/array_allocator.hpp @@ -116,7 +116,7 @@ namespace boost { pointer allocate(size_type count, const void* value = 0) { std::size_t a1 = boost::alignment_of::value; - std::size_t n1 = count * sizeof(Y) + a1 - 1; + std::size_t n1 = count * sizeof(value_type) + a1 - 1; CA ca(pair); #if !defined(BOOST_NO_CXX11_ALLOCATOR) char* p1 = CT::allocate(ca, size + n1, value); @@ -133,7 +133,7 @@ namespace boost { void deallocate(pointer memory, size_type count) { std::size_t a1 = boost::alignment_of::value; - std::size_t n1 = count * sizeof(Y) + a1 - 1; + std::size_t n1 = count * sizeof(value_type) + a1 - 1; char* p1 = reinterpret_cast(memory); CA ca(pair); #if !defined(BOOST_NO_CXX11_ALLOCATOR) @@ -143,30 +143,34 @@ namespace boost { #endif } + template + void construct(U* memory, const_reference value) { #if !defined(BOOST_NO_CXX11_ALLOCATOR) -#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \ - !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) - template - void construct(U* memory, Args&&... args) { - YT::construct(pair, memory, std::forward(args)...); - } -#else - template - void construct(U* memory, const Y& value) { YT::construct(pair, memory, value); - } -#endif - template - void destroy(U* memory) { - YT::destroy(pair, memory); - } + #else - void construct(pointer memory, const Y& value) { pair.construct(memory, value); +#endif } - void destroy(pointer memory) { + template + void destroy(U* memory) { +#if !defined(BOOST_NO_CXX11_ALLOCATOR) + YT::destroy(pair, memory); +#else pair.destroy(memory); +#endif + } + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + template + void construct(U* memory, Args&&... args) { +#if !defined(BOOST_NO_CXX11_ALLOCATOR) + YT::construct(pair, memory, std::forward(args)...); +#else + pair.construct(memory, std::forward(args)...); +#endif } #endif @@ -213,13 +217,13 @@ namespace boost { ms_allocator(std::size_t size_, type** data_) : ms_allocator_base(size_), - data(data_) { + data(data_) { } template ms_allocator(const ms_allocator& other) : ms_allocator_base(other), - data(other.data) { + data(other.data) { } pointer address(reference value) const { @@ -236,9 +240,9 @@ namespace boost { pointer allocate(size_type count, const void* = 0) { std::size_t a1 = boost::alignment_of::value; - std::size_t n1 = count * sizeof(Y)+a1 - 1; + std::size_t n1 = count * sizeof(value_type) + a1 - 1; void* p1 = ::operator new(n1 + size); - char* p2 = static_cast(p1)+n1; + char* p2 = static_cast(p1) + n1; while (std::size_t(p2) % a1 != 0) { p2--; } @@ -251,15 +255,26 @@ namespace boost { ::operator delete(p1); } - void construct(pointer memory, const Y& value) { + template + void construct(U* memory, const_reference value) { void* p1 = memory; - ::new(p1) Y(value); + ::new(p1) U(value); } - void destroy(pointer memory) { - memory->~Y(); + template + void destroy(U* memory) { + memory->~U(); } +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + template + void construct(U* memory, Args&&... args) { + void* p1 = memory; + ::new(p1) U(std::forward(args)...); + } +#endif + template bool operator==(const ms_allocator&) const { return true; diff --git a/include/boost/smart_ptr/detail/array_deleter.hpp b/include/boost/smart_ptr/detail/array_deleter.hpp index bf967a0..adaac18 100644 --- a/include/boost/smart_ptr/detail/array_deleter.hpp +++ b/include/boost/smart_ptr/detail/array_deleter.hpp @@ -87,11 +87,8 @@ namespace boost { typedef std::allocator_traits TT; #endif - void destroy(type*, std::size_t, boost::true_type) { - } - - void destroy(type* memory, std::size_t n, boost::false_type) { - for (std::size_t i = n; i > 0;) { + void destroy(type* memory, std::size_t count) { + for (std::size_t i = count; i > 0;) { #if !defined(BOOST_NO_CXX11_ALLOCATOR) TT::destroy(pair, &memory[--i]); #else @@ -100,11 +97,6 @@ namespace boost { } } - void destroy(type* memory, std::size_t n) { - boost::has_trivial_destructor tag; - destroy(memory, n, tag); - } - void value_init(type* memory, boost::true_type) { for (std::size_t i = 0; i < size; i++) { #if !defined(BOOST_NO_CXX11_ALLOCATOR) @@ -224,15 +216,15 @@ namespace boost { void destroy(type*, std::size_t, boost::true_type) { } - void destroy(type* memory, std::size_t n, boost::false_type) { - for (std::size_t i = n; i > 0;) { + void destroy(type* memory, std::size_t count, boost::false_type) { + for (std::size_t i = count; i > 0;) { memory[--i].~type(); } } - void destroy(type* memory, std::size_t n) { + void destroy(type* memory, std::size_t count) { boost::has_trivial_destructor tag; - destroy(memory, n, tag); + destroy(memory, count, tag); } void value_init(type* memory, boost::true_type) { @@ -267,6 +259,27 @@ namespace boost { value_init(memory, tag); } + template + void value_init(type* memory, const type* list) { +#if !defined(BOOST_NO_EXCEPTIONS) + std::size_t i = 0; + try { + for (; i < size; i++) { + void* p1 = memory + i; + ::new(p1) type(list[i % N]); + } + } catch (...) { + destroy(memory, i); + throw; + } +#else + for (std::size_t i = 0; i < size; i++) { + void* p1 = memory + i; + ::new(p1) type(list[i % N]); + } +#endif + } + void default_init(type*, boost::true_type) { } @@ -295,27 +308,6 @@ namespace boost { default_init(memory, tag); } - template - void value_init(type* memory, const type* list) { -#if !defined(BOOST_NO_EXCEPTIONS) - std::size_t i = 0; - try { - for (; i < size; i++) { - void* p1 = memory + i; - ::new(p1) type(list[i % N]); - } - } catch (...) { - destroy(memory, i); - throw; - } -#else - for (std::size_t i = 0; i < size; i++) { - void* p1 = memory + i; - ::new(p1) type(list[i % N]); - } -#endif - } - type* object; }; }