]>
Commit | Line | Data |
---|---|---|
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> | |
31 | class destruct_n | |
32 | { | |
33 | public: | |
34 | explicit destruct_n(T *raw) | |
35 | : m_ptr(raw), m_size() | |
36 | {} | |
37 | ||
38 | void incr() | |
39 | { | |
40 | ++m_size; | |
41 | } | |
42 | ||
43 | void incr(std::size_t n) | |
44 | { | |
45 | m_size += n; | |
46 | } | |
47 | ||
48 | void release() | |
49 | { | |
50 | m_size = 0u; | |
51 | m_ptr = 0; | |
52 | } | |
53 | ||
54 | ~destruct_n() | |
55 | { | |
56 | while(m_size--){ | |
57 | m_ptr[m_size].~T(); | |
58 | } | |
59 | } | |
60 | private: | |
61 | T *m_ptr; | |
62 | std::size_t m_size; | |
63 | }; | |
64 | ||
65 | }} //namespace boost { namespace movelib{ | |
66 | ||
67 | #endif //#ifndef BOOST_MOVE_DETAIL_DESTRUCT_N_HPP |