destruct_n.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2015-2016.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // See http://www.boost.org/libs/move for documentation.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. //! \file
  12. #ifndef BOOST_MOVE_DETAIL_DESTRUCT_N_HPP
  13. #define BOOST_MOVE_DETAIL_DESTRUCT_N_HPP
  14. #ifndef BOOST_CONFIG_HPP
  15. # include <boost/config.hpp>
  16. #endif
  17. #
  18. #if defined(BOOST_HAS_PRAGMA_ONCE)
  19. # pragma once
  20. #endif
  21. #include <cstddef>
  22. namespace boost {
  23. namespace movelib{
  24. template<class T, class RandItUninit>
  25. class destruct_n
  26. {
  27. public:
  28. explicit destruct_n(RandItUninit raw)
  29. : m_ptr(raw), m_size()
  30. {}
  31. void incr()
  32. {
  33. ++m_size;
  34. }
  35. void incr(std::size_t n)
  36. {
  37. m_size += n;
  38. }
  39. void release()
  40. {
  41. m_size = 0u;
  42. }
  43. ~destruct_n()
  44. {
  45. while(m_size--){
  46. m_ptr[m_size].~T();
  47. }
  48. }
  49. private:
  50. RandItUninit m_ptr;
  51. std::size_t m_size;
  52. };
  53. }} //namespace boost { namespace movelib{
  54. #endif //#ifndef BOOST_MOVE_DETAIL_DESTRUCT_N_HPP