Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // (C) Copyright Jonathan Turkanis 2004-2005.
0002 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0003 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
0004 
0005 // Contains the definition of move_ptrs::default_deleter, the default
0006 // Deleter template argument to move_ptr. Uses a technique of Daniel
0007 // Wallin to capture the type of a pointer at the time the deleter
0008 // is constructed, so that move_ptrs can delete objects of incomplete
0009 // type by default.
0010 
0011 #ifndef BOOST_MOVE_PTR_DEFAULT_DELETER_HPP_INCLUDED
0012 #define BOOST_MOVE_PTR_DEFAULT_DELETER_HPP_INCLUDED
0013 
0014 #include <boost/checked_delete.hpp>
0015 #include <boost/mpl/if.hpp>
0016 #include <boost/type_traits/is_array.hpp>
0017 #include <boost/type_traits/remove_bounds.hpp>
0018 
0019 namespace boost { namespace ptr_container_detail { namespace move_ptrs {
0020 
0021 namespace ptr_container_detail {
0022 
0023 template<typename T>
0024 struct deleter_base {
0025     typedef void (*deleter)(T*);
0026     deleter_base(deleter d) { delete_ = d; }
0027     void operator() (T* t) const { delete_(t); }
0028     static deleter delete_;
0029 };
0030 
0031 template<class T>
0032 typename deleter_base<T>::deleter
0033 deleter_base<T>::delete_;
0034 
0035 template<typename T>
0036 struct scalar_deleter : deleter_base<T> {
0037     typedef deleter_base<T> base;
0038     scalar_deleter() : base(do_delete) { }
0039     static void do_delete(T* t) { checked_delete(t); }
0040 };
0041 
0042 template<typename T>
0043 struct array_deleter
0044     : deleter_base<typename remove_bounds<T>::type>
0045 {
0046     typedef typename remove_bounds<T>::type element_type;
0047     typedef deleter_base<element_type> base;
0048     array_deleter() : base(do_delete) { }
0049     static void do_delete(element_type* t) { checked_array_delete(t); }
0050 };
0051 
0052 } // End namespace ptr_container_detail.
0053 
0054 template<typename T>
0055 struct default_deleter
0056     : mpl::if_<
0057           is_array<T>,
0058           ptr_container_detail::array_deleter<T>,
0059           ptr_container_detail::scalar_deleter<T>
0060       >::type
0061 {
0062     default_deleter() { }
0063     template<typename TT>
0064     default_deleter(default_deleter<TT>) { }
0065 };
0066 
0067 } } } // End namespaces ptr_container_detail, move_ptrs, boost.
0068 
0069 #endif // #ifndef BOOST_MOVE_PTR_DEFAULT_DELETER_HPP_INCLUDED