forked from boostorg/core
Use a different workaround for supporting noinit_adaptor in C++03
This commit is contained in:
@@ -26,16 +26,6 @@ struct A2 {
|
||||
};
|
||||
#endif
|
||||
|
||||
template<class T>
|
||||
struct A3 {
|
||||
typedef T value_type;
|
||||
A3() { }
|
||||
template<class U>
|
||||
void construct(U* p) {
|
||||
::new((void*)p) U(1);
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
@@ -52,11 +42,5 @@ int main()
|
||||
BOOST_TEST_EQ(i, 6);
|
||||
}
|
||||
#endif
|
||||
{
|
||||
A3<int> a;
|
||||
int i = 0;
|
||||
boost::allocator_construct(a, &i);
|
||||
BOOST_TEST_EQ(i, 1);
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@@ -8,23 +8,59 @@ Distributed under the Boost Software License, Version 1.0.
|
||||
#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;
|
||||
|
||||
template<class T>
|
||||
struct A {
|
||||
struct A1 {
|
||||
typedef T value_type;
|
||||
A() { }
|
||||
A1() { }
|
||||
};
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
template<class T>
|
||||
struct A2 {
|
||||
typedef T value_type;
|
||||
A2() { }
|
||||
template<class U>
|
||||
void destroy(U* p) {
|
||||
*p = U();
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
A<int> 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<int> 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<int> 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();
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ struct A1 {
|
||||
A1() { }
|
||||
};
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
template<class T>
|
||||
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<int> a;
|
||||
int i = 5;
|
||||
boost::allocator_destroy(a, &i);
|
||||
BOOST_TEST_EQ(i, 0);
|
||||
}
|
||||
#endif
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
Reference in New Issue
Block a user