2020-04-13 01:43:43 -04:00
|
|
|
/*
|
|
|
|
Copyright 2020 Glen Joseph Fernandes
|
|
|
|
(glenjofe@gmail.com)
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0.
|
|
|
|
(http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
*/
|
|
|
|
#include <boost/core/allocator_access.hpp>
|
|
|
|
#include <boost/core/lightweight_test.hpp>
|
|
|
|
|
|
|
|
struct S {
|
|
|
|
static int count;
|
|
|
|
S() {
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
S(const S&) {
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
~S() {
|
|
|
|
--count;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int S::count = 0;
|
|
|
|
|
2020-05-25 15:00:18 -04:00
|
|
|
template<class T>
|
|
|
|
struct A1 {
|
|
|
|
typedef T value_type;
|
|
|
|
A1() { }
|
|
|
|
};
|
2020-04-13 01:43:43 -04:00
|
|
|
|
2022-03-15 11:58:38 -04:00
|
|
|
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
2020-05-25 15:00:18 -04:00
|
|
|
template<class T>
|
2020-04-13 01:43:43 -04:00
|
|
|
struct A2 {
|
2020-05-25 15:00:18 -04:00
|
|
|
typedef T value_type;
|
|
|
|
A2() { }
|
|
|
|
template<class U>
|
|
|
|
void destroy(U* p) {
|
|
|
|
*p = U();
|
2020-04-13 01:43:43 -04:00
|
|
|
}
|
|
|
|
};
|
2022-03-15 11:58:38 -04:00
|
|
|
#endif
|
2020-04-13 01:43:43 -04:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
{
|
2020-05-25 15:00:18 -04:00
|
|
|
A1<int> a;
|
|
|
|
S s;
|
|
|
|
boost::allocator_destroy(a, &s);
|
2020-04-13 01:43:43 -04:00
|
|
|
BOOST_TEST_EQ(S::count, 0);
|
2020-05-25 15:00:18 -04:00
|
|
|
::new((void*)&s) S();
|
2020-04-13 01:43:43 -04:00
|
|
|
}
|
2022-03-15 11:58:38 -04:00
|
|
|
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
2020-04-13 01:43:43 -04:00
|
|
|
{
|
2022-03-12 00:51:52 -05:00
|
|
|
A2<int> a;
|
2020-05-25 15:00:18 -04:00
|
|
|
int i = 5;
|
|
|
|
boost::allocator_destroy(a, &i);
|
|
|
|
BOOST_TEST_EQ(i, 0);
|
2020-04-13 01:43:43 -04:00
|
|
|
}
|
2022-03-15 11:58:38 -04:00
|
|
|
#endif
|
2020-04-13 01:43:43 -04:00
|
|
|
return boost::report_errors();
|
|
|
|
}
|