1 /*
2 Copyright 2019 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/alloc_construct.hpp>
9 #include <boost/core/default_allocator.hpp>
10 #include <boost/core/lightweight_test.hpp>
11 
12 class type {
13 public:
type()14     type() {
15         if (count == 4) {
16             throw true;
17         }
18         ++count;
19     }
20 
~type()21     ~type() {
22         --count;
23     }
24 
25     static int count;
26 
27 private:
28     type(const type&);
29     type& operator=(const type&);
30 };
31 
32 int type::count = 0;
33 
main()34 int main()
35 {
36     boost::default_allocator<type> a;
37     type* p = a.allocate(5);
38     try {
39         boost::alloc_construct_n(a, p, 5);
40         BOOST_ERROR("construct_n did not throw");
41     } catch (...) {
42         BOOST_TEST_EQ(type::count, 0);
43     }
44     a.deallocate(p, 5);
45     return boost::report_errors();
46 }
47