| 1 | /* |
| 2 | Copyright 2022 Glen Joseph Fernandes |
| 3 | (glenjofe@gmail.com) |
| 4 | |
| 5 | Distributed under the Boost Software License, Version 1.0. |
| 6 | (http://www.boost.org/LICENSE_1_0.txt) |
| 7 | */ |
| 8 | #include <boost/core/allocator_access.hpp> |
| 9 | #include <boost/core/lightweight_test.hpp> |
| 10 | |
| 11 | struct S { |
| 12 | static int count; |
| 13 | S() { |
| 14 | ++count; |
| 15 | } |
| 16 | S(const S&) { |
| 17 | ++count; |
| 18 | } |
| 19 | ~S() { |
| 20 | --count; |
| 21 | } |
| 22 | }; |
| 23 | |
| 24 | int S::count = 0; |
| 25 | |
| 26 | template<class T> |
| 27 | struct A1 { |
| 28 | typedef T value_type; |
| 29 | A1() { } |
| 30 | }; |
| 31 | |
| 32 | #if !defined(BOOST_NO_CXX11_ALLOCATOR) |
| 33 | template<class T> |
| 34 | struct A2 { |
| 35 | typedef T value_type; |
| 36 | A2() { } |
| 37 | template<class U> |
| 38 | void destroy(U* p) { |
| 39 | *p = U(); |
| 40 | } |
| 41 | }; |
| 42 | #endif |
| 43 | |
| 44 | int main() |
| 45 | { |
| 46 | { |
| 47 | A1<int> a; |
| 48 | S s[3]; |
| 49 | boost::allocator_destroy_n(a, p: &s[0], n: 3); |
| 50 | BOOST_TEST_EQ(S::count, 0); |
| 51 | ::new((void*)&s[0]) S(); |
| 52 | ::new((void*)&s[1]) S(); |
| 53 | ::new((void*)&s[2]) S(); |
| 54 | } |
| 55 | #if !defined(BOOST_NO_CXX11_ALLOCATOR) |
| 56 | { |
| 57 | A2<int> a; |
| 58 | int i[3] = { 5, 5, 5 }; |
| 59 | boost::allocator_destroy_n(a, p: &i[0], n: 3); |
| 60 | BOOST_TEST_EQ(i[0], 0); |
| 61 | BOOST_TEST_EQ(i[1], 0); |
| 62 | BOOST_TEST_EQ(i[2], 0); |
| 63 | } |
| 64 | #endif |
| 65 | return boost::report_errors(); |
| 66 | } |
| 67 | |