]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/align/test/aligned_delete_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / align / test / aligned_delete_test.cpp
CommitLineData
7c673cae
FG
1/*
2(c) 2014 Glen Joseph Fernandes
3<glenjofe -at- gmail.com>
4
5Distributed under the Boost Software
6License, Version 1.0.
7http://boost.org/LICENSE_1_0.txt
8*/
9#include <boost/align/aligned_alloc.hpp>
10#include <boost/align/aligned_delete.hpp>
11#include <boost/align/alignment_of.hpp>
12#include <boost/core/lightweight_test.hpp>
13#include <new>
14
15template<class T>
16class type {
17public:
18 static int count;
19 type()
20 : value() {
21 count++;
22 }
23 ~type() {
24 count--;
25 }
26private:
27 T value;
28};
29
30template<class T>
31int type<T>::count = 0;
32
33template<class T>
34T* aligned_new()
35{
36 void* p = boost::alignment::aligned_alloc(boost::
37 alignment::alignment_of<T>::value, sizeof(T));
38 if (p) {
39 return ::new(p) T();
40 } else {
41 return 0;
42 }
43}
44
45template<class T>
46void test()
47{
48 type<T>* p = aligned_new<type<T> >();
49 BOOST_TEST(type<T>::count == 1);
50 boost::alignment::aligned_delete()(p);
51 BOOST_TEST(type<T>::count == 0);
52}
53
54class C { };
55union U { };
56
57int main()
58{
59 test<char>();
60 test<bool>();
61 test<short>();
62 test<int>();
63 test<long>();
64 test<float>();
65 test<double>();
66 test<long double>();
67 test<void*>();
68 test<void(*)()>();
69 test<C>();
70 test<int C::*>();
71 test<int (C::*)()>();
72 test<U>();
73
74 return boost::report_errors();
75}