1 /*
2 Copyright 2020 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 template<class T>
12 struct A1 {
13     typedef T value_type;
14     typedef std::size_t size_type;
15     typedef T* pointer;
16     typedef const T* const_pointer;
17     template<class U>
18     struct rebind {
19         typedef A1<U> other;
20     };
A1A121     A1()
22         : value() { }
allocateA123     T* allocate(std::size_t n, const void*) {
24         value = n;
25         return 0;
26     }
27     std::size_t value;
28 };
29 
30 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
31 template<class T>
32 struct A2 {
33     typedef T value_type;
A2A234     A2()
35         : value() { }
allocateA236     T* allocate(std::size_t n) {
37         value = n;
38         return 0;
39     }
40     std::size_t value;
41 };
42 #endif
43 
main()44 int main()
45 {
46     {
47         A1<int> a;
48         BOOST_TEST_NOT(boost::allocator_allocate(a, 5, 0));
49         BOOST_TEST_EQ(a.value, 5);
50     }
51 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
52     {
53         A2<int> a;
54         BOOST_TEST_NOT(boost::allocator_allocate(a, 5, 0));
55         BOOST_TEST_EQ(a.value, 5);
56     }
57 #endif
58     return boost::report_errors();
59 }
60