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_CLONE_ALLOCATOR_HPP
13 #define BOOST_PTR_CONTAINER_CLONE_ALLOCATOR_HPP
15 #include <boost/assert.hpp>
16 #include <boost/checked_delete.hpp>
21 /////////////////////////////////////////////////////////////////////////
23 /////////////////////////////////////////////////////////////////////////
26 inline T
* new_clone( const T
& r
)
29 // @remark: if you get a compile-error here,
30 // it is most likely because you did not
31 // define new_clone( const T& ) in the namespace
35 BOOST_ASSERT( typeid(r
) == typeid(*res
) &&
36 "Default new_clone() sliced object!" );
41 inline T
* new_clone( const T
* r
)
43 return r
? new_clone( *r
) : 0;
47 // @remark: to make new_clone() work
48 // with scope_ptr/shared_ptr ect.
49 // simply overload for those types
50 // in the appropriate namespace.
54 inline void delete_clone( const T
* r
)
59 /////////////////////////////////////////////////////////////////////////
60 // CloneAllocator concept
61 /////////////////////////////////////////////////////////////////////////
63 struct heap_clone_allocator
66 static U
* allocate_clone( const U
& r
)
68 return new_clone( r
);
72 static void deallocate_clone( const U
* r
)
81 struct view_clone_allocator
84 static U
* allocate_clone( const U
& r
)
86 return const_cast<U
*>(&r
);
90 static void deallocate_clone( const U
* /*r*/ )
96 } // namespace 'boost'