Update test allocators to be C++11 compliant by making them templates on the pointer type

This commit is contained in:
Christian Mazakas
2022-05-20 14:07:44 -07:00
parent e7d34a5ab1
commit 0bcc79baab
4 changed files with 91 additions and 68 deletions

View File

@ -1,5 +1,6 @@
// Copyright 2006-2011 Daniel James. // Copyright 2006-2011 Daniel James.
// Copyright 2022 Christian Mazakas
// Distributed under the Boost Software License, Version 1.0. (See accompanying // Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@ -213,25 +214,27 @@ namespace test
::operator delete((void*)p); ::operator delete((void*)p);
} }
void construct(T* p, T const& t) #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class U, class V>
void construct(U* p, V const& v)
{ {
detail::tracker.track_construct((void*)p, sizeof(T), tag_); detail::tracker.track_construct((void*)p, sizeof(U), tag_);
new (p) T(t); new (p) U(v);
} }
#else
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template <class U, typename... Args>
template <typename... Args> void construct(U* p, BOOST_FWD_REF(Args)... args)
void construct(T* p, BOOST_FWD_REF(Args)... args)
{ {
detail::tracker.track_construct((void*)p, sizeof(T), tag_); detail::tracker.track_construct((void*)p, sizeof(U), tag_);
new (p) T(boost::forward<Args>(args)...); new (p) U(boost::forward<Args>(args)...);
} }
#endif #endif
void destroy(T* p) template <class U>
void destroy(U* p)
{ {
detail::tracker.track_destroy((void*)p, sizeof(T), tag_); detail::tracker.track_destroy((void*)p, sizeof(U), tag_);
p->~T(); p->~U();
} }
size_type max_size() const size_type max_size() const

View File

@ -1,5 +1,6 @@
// Copyright 2006-2009 Daniel James. // Copyright 2006-2009 Daniel James.
// Copyright 2022 Christian Mazakas
// Distributed under the Boost Software License, Version 1.0. (See accompanying // Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@ -475,32 +476,34 @@ namespace test {
} }
} }
void construct(pointer p, T const& t) #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class U, class Arg>
void construct(U* p, Arg const& t)
{ {
UNORDERED_SCOPE(allocator::construct(T*, T)) UNORDERED_SCOPE(allocator::construct(U*, Arg))
{ {
UNORDERED_EPOINT("Mock allocator construct function."); UNORDERED_EPOINT("Mock allocator construct function.");
new (p) T(t); new (p) U(t);
} }
test::detail::tracker.track_construct((void*)p, sizeof(T), tag_); test::detail::tracker.track_construct((void*)p, sizeof(U), tag_);
} }
#else
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template <class U, class... Args> void construct(U* p, BOOST_FWD_REF(Args)... args)
template <class... Args> void construct(T* p, BOOST_FWD_REF(Args)... args)
{ {
UNORDERED_SCOPE(allocator::construct(pointer, BOOST_FWD_REF(Args)...)) UNORDERED_SCOPE(allocator::construct(U*, BOOST_FWD_REF(Args)...))
{ {
UNORDERED_EPOINT("Mock allocator construct function."); UNORDERED_EPOINT("Mock allocator construct function.");
new (p) T(boost::forward<Args>(args)...); new (p) U(boost::forward<Args>(args)...);
} }
test::detail::tracker.track_construct((void*)p, sizeof(T), tag_); test::detail::tracker.track_construct((void*)p, sizeof(U), tag_);
} }
#endif #endif
void destroy(T* p) template <class U>
void destroy(U* p)
{ {
test::detail::tracker.track_destroy((void*)p, sizeof(T), tag_); test::detail::tracker.track_destroy((void*)p, sizeof(U), tag_);
p->~T(); p->~U();
} }
size_type max_size() const size_type max_size() const
@ -654,32 +657,35 @@ namespace test {
} }
} }
void construct(pointer p, T const& t) #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class U, class V>
void construct(U* p, V const& v)
{ {
UNORDERED_SCOPE(allocator2::construct(T*, T)) UNORDERED_SCOPE(allocator2::construct(U*, V))
{ {
UNORDERED_EPOINT("Mock allocator2 construct function."); UNORDERED_EPOINT("Mock allocator2 construct function.");
new (p) T(t); new (p) U(v);
} }
test::detail::tracker.track_construct((void*)p, sizeof(T), tag_); test::detail::tracker.track_construct((void*)p, sizeof(U), tag_);
} }
#else
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template <class U, class... Args>
template <class... Args> void construct(T* p, BOOST_FWD_REF(Args)... args) void construct(U* p, BOOST_FWD_REF(Args)... args)
{ {
UNORDERED_SCOPE(allocator2::construct(pointer, BOOST_FWD_REF(Args)...)) UNORDERED_SCOPE(allocator2::construct(U*, BOOST_FWD_REF(Args)...))
{ {
UNORDERED_EPOINT("Mock allocator2 construct function."); UNORDERED_EPOINT("Mock allocator2 construct function.");
new (p) T(boost::forward<Args>(args)...); new (p) U(boost::forward<Args>(args)...);
} }
test::detail::tracker.track_construct((void*)p, sizeof(T), tag_); test::detail::tracker.track_construct((void*)p, sizeof(U), tag_);
} }
#endif #endif
void destroy(T* p) template <class U>
void destroy(U* p)
{ {
test::detail::tracker.track_destroy((void*)p, sizeof(T), tag_); test::detail::tracker.track_destroy((void*)p, sizeof(U), tag_);
p->~T(); p->~U();
} }
size_type max_size() const size_type max_size() const

View File

@ -1,5 +1,6 @@
// Copyright 2006-2009 Daniel James. // Copyright 2006-2009 Daniel James.
// Copyright 2022 Christian Mazakas
// Distributed under the Boost Software License, Version 1.0. (See accompanying // Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@ -428,16 +429,20 @@ namespace test {
::operator delete((void*)p.ptr_); ::operator delete((void*)p.ptr_);
} }
void construct(T* p, T const& t) { new ((void*)p) T(t); } #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class U, class V> void construct(U* p, V const& v)
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class... Args> void construct(T* p, BOOST_FWD_REF(Args)... args)
{ {
new ((void*)p) T(boost::forward<Args>(args)...); new ((void*)p) U(v);
}
#else
template <class U, class... Args>
void construct(U* p, BOOST_FWD_REF(Args)... args)
{
new ((void*)p) U(boost::forward<Args>(args)...);
} }
#endif #endif
void destroy(T* p) { p->~T(); } template <class U> void destroy(U* p) { p->~U(); }
size_type max_size() const { return 1000; } size_type max_size() const { return 1000; }
@ -498,17 +503,20 @@ namespace test {
::operator delete((void*)p.ptr_); ::operator delete((void*)p.ptr_);
} }
void construct(T const* p, T const& t) { new ((void*)p) T(t); } #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class U> void construct(U* p, U const& t)
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class... Args>
void construct(T const* p, BOOST_FWD_REF(Args)... args)
{ {
new ((void*)p) T(boost::forward<Args>(args)...); new (p) U(t);
}
#else
template <class U, class... Args>
void construct(U* p, BOOST_FWD_REF(Args)... args)
{
new (p) U(boost::forward<Args>(args)...);
} }
#endif #endif
void destroy(T const* p) { p->~T(); } template <class U> void destroy(U* p) { p->~U(); }
size_type max_size() const { return 1000; } size_type max_size() const { return 1000; }
@ -573,16 +581,20 @@ namespace test {
void deallocate(T* p, std::size_t) { ::operator delete((void*)p); } void deallocate(T* p, std::size_t) { ::operator delete((void*)p); }
void construct(T* p, T const& t) { new ((void*)p) T(t); } #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class U, class V> void construct(U* p, V const& v)
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class... Args> void construct(T* p, BOOST_FWD_REF(Args)... args)
{ {
new ((void*)p) T(boost::forward<Args>(args)...); new ((void*)p) U(v);
}
#else
template <class U, class... Args>
void construct(U* p, BOOST_FWD_REF(Args)... args)
{
new ((void*)p) U(boost::forward<Args>(args)...);
} }
#endif #endif
void destroy(T* p) { p->~T(); } template <class U> void destroy(U* p) { p->~U(); }
std::size_t max_size() const { return 1000u; } std::size_t max_size() const { return 1000u; }
}; };

View File

@ -1,5 +1,6 @@
// Copyright 2006-2009 Daniel James. // Copyright 2006-2009 Daniel James.
// Copyright 2022 Christian Mazakas
// Distributed under the Boost Software License, Version 1.0. (See accompanying // Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@ -646,24 +647,25 @@ namespace test {
::operator delete((void*)p.ptr_); ::operator delete((void*)p.ptr_);
} }
void construct(T* p, T const& t) #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template <class U, class V> void construct(U* p, V const& v)
{ {
detail::tracker.track_construct((void*)p, sizeof(T), tag_); detail::tracker.track_construct((void*)p, sizeof(U), tag_);
new (p) T(t); new (p) U(v);
} }
#else
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template <class U, class... Args>
template <class... Args> void construct(T* p, BOOST_FWD_REF(Args)... args) void construct(U* p, BOOST_FWD_REF(Args)... args)
{ {
detail::tracker.track_construct((void*)p, sizeof(T), tag_); detail::tracker.track_construct((void*)p, sizeof(U), tag_);
new (p) T(boost::forward<Args>(args)...); new (p) U(boost::forward<Args>(args)...);
} }
#endif #endif
void destroy(T* p) template <class U> void destroy(U* p)
{ {
detail::tracker.track_destroy((void*)p, sizeof(T), tag_); detail::tracker.track_destroy((void*)p, sizeof(U), tag_);
p->~T(); p->~U();
} }
size_type max_size() const size_type max_size() const