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 12 //! \file 13 14 #ifndef BOOST_MOVE_DETAIL_DESTRUCT_N_HPP 15 #define BOOST_MOVE_DETAIL_DESTRUCT_N_HPP 16 17 #ifndef BOOST_CONFIG_HPP 18 # include <boost/config.hpp> 19 #endif 20 # 21 #if defined(BOOST_HAS_PRAGMA_ONCE) 22 # pragma once 23 #endif 24 25 #include <cstddef> 26 27 namespace boost { 28 namespace movelib{ 29 30 template<class T, class RandItUninit> 31 class destruct_n 32 { 33 public: destruct_n(RandItUninit raw)34 explicit destruct_n(RandItUninit raw) 35 : m_ptr(raw), m_size() 36 {} 37 incr()38 void incr() 39 { 40 ++m_size; 41 } 42 incr(std::size_t n)43 void incr(std::size_t n) 44 { 45 m_size += n; 46 } 47 release()48 void release() 49 { 50 m_size = 0u; 51 } 52 ~destruct_n()53 ~destruct_n() 54 { 55 while(m_size--){ 56 m_ptr[m_size].~T(); 57 } 58 } 59 private: 60 RandItUninit m_ptr; 61 std::size_t m_size; 62 }; 63 64 }} //namespace boost { namespace movelib{ 65 66 #endif //#ifndef BOOST_MOVE_DETAIL_DESTRUCT_N_HPP 67