aligned_delete_test.cpp 1.1 KB

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