1
2// vim:sw=2:ai
3
4/*
5 * Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved.
6 * See COPYRIGHT.txt for details.
7 */
8
9#ifndef DENA_AUTO_PTRCONTAINER_HPP
10#define DENA_AUTO_PTRCONTAINER_HPP
11
12namespace dena {
13
14template <typename Tcnt>
15struct auto_ptrcontainer {
16 typedef Tcnt container_type;
17 typedef typename container_type::value_type value_type;
18 typedef typename container_type::pointer pointer;
19 typedef typename container_type::reference reference;
20 typedef typename container_type::const_reference const_reference;
21 typedef typename container_type::size_type size_type;
22 typedef typename container_type::difference_type difference_type;
23 typedef typename container_type::iterator iterator;
24 typedef typename container_type::const_iterator const_iterator;
25 typedef typename container_type::reverse_iterator reverse_iterator;
26 typedef typename container_type::const_reverse_iterator
27 const_reverse_iterator;
28 iterator begin() { return cnt.begin(); }
29 const_iterator begin() const { return cnt.begin(); }
30 iterator end() { return cnt.end(); }
31 const_iterator end() const { return cnt.end(); }
32 reverse_iterator rbegin() { return cnt.rbegin(); }
33 reverse_iterator rend() { return cnt.rend(); }
34 const_reverse_iterator rbegin() const { return cnt.rbegin(); }
35 const_reverse_iterator rend() const { return cnt.rend(); }
36 size_type size() const { return cnt.size(); }
37 size_type max_size() const { return cnt.max_size(); }
38 bool empty() const { return cnt.empty(); }
39 reference front() { return cnt.front(); }
40 const_reference front() const { cnt.front(); }
41 reference back() { return cnt.back(); }
42 const_reference back() const { cnt.back(); }
43 void swap(auto_ptrcontainer& x) { cnt.swap(x.cnt); }
44 ~auto_ptrcontainer() {
45 for (iterator i = begin(); i != end(); ++i) {
46 delete *i;
47 }
48 }
49 template <typename Tap> void push_back_ptr(Tap& ap) {
50 cnt.push_back(ap.get());
51 ap.release();
52 }
53 void erase_ptr(iterator i) {
54 delete *i;
55 cnt.erase(i);
56 }
57 reference operator [](size_type n) { return cnt[n]; }
58 const_reference operator [](size_type n) const { return cnt[n]; }
59 void clear() { cnt.clear(); }
60 private:
61 Tcnt cnt;
62};
63
64};
65
66#endif
67
68