File indexing completed on 2025-01-18 09:50:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_PTR_CONTAINER_CLONE_ALLOCATOR_HPP
0013 #define BOOST_PTR_CONTAINER_CLONE_ALLOCATOR_HPP
0014
0015 #include <boost/assert.hpp>
0016 #include <boost/checked_delete.hpp>
0017 #include <typeinfo>
0018
0019 namespace boost
0020 {
0021
0022
0023
0024
0025 template< class T >
0026 inline T* new_clone( const T& r )
0027 {
0028
0029
0030
0031
0032
0033
0034 T* res = new T( r );
0035 BOOST_ASSERT( typeid(r) == typeid(*res) &&
0036 "Default new_clone() sliced object!" );
0037 return res;
0038 }
0039
0040
0041
0042 template< class T >
0043 inline void delete_clone( const T* r )
0044 {
0045 checked_delete( r );
0046 }
0047
0048
0049
0050
0051
0052 struct heap_clone_allocator
0053 {
0054 template< class U >
0055 static U* allocate_clone( const U& r )
0056 {
0057 return new_clone( r );
0058 }
0059
0060 template< class U >
0061 static void deallocate_clone( const U* r )
0062 {
0063 delete_clone( r );
0064 }
0065
0066 };
0067
0068
0069
0070 struct view_clone_allocator
0071 {
0072 template< class U >
0073 static U* allocate_clone( const U& r )
0074 {
0075 return const_cast<U*>(&r);
0076 }
0077
0078 template< class U >
0079 static void deallocate_clone( const U* )
0080 {
0081
0082 }
0083 };
0084
0085 }
0086
0087 #endif
0088