• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 // Copyright 2018 Daniel James.
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #include <boost/detail/allocator_utilities.hpp>
7 #include <boost/static_assert.hpp>
8 #include <boost/core/allocator_access.hpp>
9 #include <boost/core/lightweight_test.hpp>
10 #include <boost/type_traits/is_same.hpp>
11 #include <memory>
12 
13 typedef std::allocator<int> std_int_allocator;
14 typedef boost::detail::allocator::rebind_to<std_int_allocator, char>::type char_allocator;
15 typedef boost::detail::allocator::rebind_to<char_allocator, int>::type int_allocator;
16 typedef boost::detail::allocator::rebind_to<int_allocator, char>::type char_allocator2;
17 
main()18 int main()
19 {
20     BOOST_STATIC_ASSERT((!boost::is_same<char_allocator, int_allocator>::value));
21     BOOST_STATIC_ASSERT((boost::is_same<char_allocator, char_allocator2>::value));
22 
23     // Check the constructors works okay
24     std_int_allocator a1;
25     char_allocator a2(a1);
26     char_allocator a2a(a2);
27     int_allocator a3(a2);
28 
29     // Check allocate works okay
30     {
31         boost::allocator_pointer<char_allocator>::type p = a2.allocate(10);
32         BOOST_TEST(!!p);
33         a2.deallocate(p, 10);
34     }
35 
36     // Try using the standalone construct/destroy
37     {
38         boost::allocator_pointer<int_allocator>::type p2 = a3.allocate(1);
39         boost::detail::allocator::construct(p2, 25);
40         BOOST_TEST(*p2 == 25);
41         boost::detail::allocator::destroy(p2);
42         a3.deallocate(p2, 1);
43     }
44 
45     return boost::report_errors();
46 }
47