1 /* 2 Copyright 2014 Glen Joseph Fernandes 3 ([email protected]) 4 5 Distributed under the Boost Software License, Version 1.0. 6 (http://www.boost.org/LICENSE_1_0.txt) 7 */ 8 #include <boost/align/aligned_alloc.hpp> 9 #include <boost/align/aligned_delete.hpp> 10 #include <boost/align/alignment_of.hpp> 11 #include <boost/core/lightweight_test.hpp> 12 #include <new> 13 14 class type { 15 public: 16 static unsigned count; 17 type()18 type() { 19 ++count; 20 } 21 ~type()22 ~type() { 23 --count; 24 } 25 26 private: 27 type(const type&); 28 type& operator=(const type&); 29 }; 30 31 unsigned type::count = 0; 32 main()33int main() 34 { 35 { 36 void* p = boost::alignment::aligned_alloc(1, 1); 37 char* q = ::new(p) char; 38 boost::alignment::aligned_delete()(q); 39 } 40 { 41 enum { 42 N = boost::alignment::alignment_of<type>::value 43 }; 44 void* p = boost::alignment::aligned_alloc(N, sizeof(type)); 45 type* q = ::new(p) type; 46 BOOST_TEST(type::count == 1); 47 boost::alignment::aligned_delete()(q); 48 BOOST_TEST(type::count == 0); 49 } 50 return boost::report_errors(); 51 } 52