]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/core/test/alloc_construct_cxx11_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / core / test / alloc_construct_cxx11_test.cpp
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/config.hpp>
9 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
10 #include <boost/core/alloc_construct.hpp>
11 #include <boost/core/lightweight_test.hpp>
12
13 #if defined(_MSC_VER)
14 # pragma warning(disable: 4100) // unreferenced parameter 'ptr'
15 #endif
16
17 class type {
18 public:
19 explicit type(int x)
20 : value_(x) { }
21
22 int value() const {
23 return value_;
24 }
25
26 static int count;
27
28 private:
29 type(const type&);
30 type& operator=(const type&);
31
32 int value_;
33 };
34
35 int type::count = 0;
36
37 template<class T>
38 struct creator {
39 typedef T value_type;
40
41 creator() { }
42
43 template<class U>
44 creator(const creator<U>&) { }
45
46 T* allocate(std::size_t size) {
47 return static_cast<T*>(::operator new(sizeof(T) * size));
48 }
49
50 void deallocate(T* ptr, std::size_t) {
51 ::operator delete(ptr);
52 }
53
54 template<class V>
55 void construct(type* ptr, const V& value) {
56 ::new(static_cast<void*>(ptr)) type(value + 1);
57 ++type::count;
58 }
59
60 void destroy(type* ptr) {
61 ptr->~type();
62 --type::count;
63 }
64 };
65
66 int main()
67 {
68 creator<type> a;
69 type* p = a.allocate(1);
70 boost::alloc_construct(a, p, 1);
71 BOOST_TEST_EQ(type::count, 1);
72 BOOST_TEST_EQ(p->value(), 2);
73 boost::alloc_destroy(a, p);
74 BOOST_TEST_EQ(type::count, 0);
75 return boost::report_errors();
76 }
77 #else
78 int main()
79 {
80 return 0;
81 }
82 #endif