2 // Boost.Pointer Container
4 // Copyright Thorsten Ottosen 2003-2005. Use, modification and
5 // distribution is subject to the Boost Software License, Version
6 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // For more information, see http://www.boost.org/libs/ptr_container/
12 #ifndef BOOST_PTR_CONTAINER_SCOPED_DELETER_HPP
13 #define BOOST_PTR_CONTAINER_SCOPED_DELETER_HPP
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
21 #include <boost/scoped_array.hpp>
26 namespace ptr_container_detail
28 template< class Container >
31 typedef BOOST_DEDUCED_TYPENAME Container::size_type size_type;
32 typedef BOOST_DEDUCED_TYPENAME Container::object_type T;
35 scoped_array<T*> ptrs_;
40 scoped_deleter( Container& cont, T** a, size_type size )
49 scoped_deleter( Container& cont, size_type size )
51 ptrs_( new T*[size] ),
55 BOOST_ASSERT( size > 0 );
60 scoped_deleter( Container& cont, size_type n, const T& x ) // strong
66 for( size_type i = 0; i != n; i++ )
67 add( cont_.null_policy_allocate_clone( &x ) );
68 BOOST_ASSERT( stored_ > 0 );
73 template< class InputIterator >
74 scoped_deleter ( Container& cont, InputIterator first, InputIterator last ) // strong
76 ptrs_( new T*[ std::distance(first,last) ] ),
80 for( ; first != last; ++first )
81 add( cont_.null_policy_allocate_clone_from_iterator( first ) );
82 BOOST_ASSERT( stored_ > 0 );
91 for( size_type i = 0u; i != stored_; ++i )
92 cont_.null_policy_deallocate_clone( ptrs_[i] );
100 BOOST_ASSERT( ptrs_.get() != 0 );
116 BOOST_ASSERT( ptrs_.get() != 0 );
124 BOOST_ASSERT( ptrs_.get() != 0 );
125 return &ptrs_[stored_];
128 }; // class 'scoped_deleter'