Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:35

0001 //
0002 // Boost.Pointer Container
0003 //
0004 //  Copyright Thorsten Ottosen 2003-2005. Use, modification and
0005 //  distribution is subject to the Boost Software License, Version
0006 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
0007 //  http://www.boost.org/LICENSE_1_0.txt)
0008 //
0009 // For more information, see http://www.boost.org/libs/ptr_container/
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     // Clonable concept
0023     /////////////////////////////////////////////////////////////////////////
0024 
0025     template< class T >
0026     inline T* new_clone( const T& r )
0027     {
0028         //
0029         // @remark: if you get a compile-error here,
0030         //          it is most likely because you did not
0031         //          define new_clone( const T& ) in the namespace
0032         //          of T.
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     // CloneAllocator concept
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* /*r*/ )
0080         {
0081             // do nothing
0082         }
0083     };
0084 
0085 } // namespace 'boost'
0086 
0087 #endif
0088