epoc32/include/stdapis/boost/ptr_container/detail/default_deleter.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/ptr_container/detail/default_deleter.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,69 @@
     1.4 +// (C) Copyright Jonathan Turkanis 2004-2005.
     1.5 +// Distributed under the Boost Software License, Version 1.0. (See accompanying
     1.6 +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
     1.7 +
     1.8 +// Contains the definition of move_ptrs::default_deleter, the default
     1.9 +// Deleter template argument to move_ptr. Uses a technique of Daniel
    1.10 +// Wallin to capture the type of a pointer at the time the deleter 
    1.11 +// is constructed, so that move_ptrs can delete objects of incomplete 
    1.12 +// type by default.
    1.13 +
    1.14 +#ifndef BOOST_MOVE_PTR_DEFAULT_DELETER_HPP_INCLUDED
    1.15 +#define BOOST_MOVE_PTR_DEFAULT_DELETER_HPP_INCLUDED 
    1.16 +
    1.17 +#include <boost/checked_delete.hpp>
    1.18 +#include <boost/mpl/if.hpp>
    1.19 +#include <boost/type_traits/is_array.hpp>
    1.20 +#include <boost/type_traits/remove_bounds.hpp>
    1.21 +
    1.22 +namespace boost { namespace ptr_container_detail { namespace move_ptrs {
    1.23 +
    1.24 +namespace ptr_container_detail {
    1.25 +
    1.26 +template<typename T>
    1.27 +struct deleter_base {
    1.28 +    typedef void (*deleter)(T*);
    1.29 +    deleter_base(deleter d) { delete_ = d; }
    1.30 +    void operator() (T* t) const { delete_(t); }
    1.31 +    static deleter delete_;
    1.32 +};
    1.33 +
    1.34 +template<class T>
    1.35 +typename deleter_base<T>::deleter 
    1.36 +deleter_base<T>::delete_;
    1.37 +
    1.38 +template<typename T>
    1.39 +struct scalar_deleter : deleter_base<T> {
    1.40 +    typedef deleter_base<T> base;
    1.41 +    scalar_deleter() : base(do_delete) { }
    1.42 +    static void do_delete(T* t) { checked_delete(t); }
    1.43 +};
    1.44 +
    1.45 +template<typename T>
    1.46 +struct array_deleter 
    1.47 +    : deleter_base<typename remove_bounds<T>::type>
    1.48 +{
    1.49 +    typedef typename remove_bounds<T>::type element_type;
    1.50 +    typedef deleter_base<element_type> base;
    1.51 +    array_deleter() : base(do_delete) { }
    1.52 +    static void do_delete(element_type* t) { checked_array_delete(t); }
    1.53 +};
    1.54 +
    1.55 +} // End namespace ptr_container_detail.
    1.56 +
    1.57 +template<typename T>
    1.58 +struct default_deleter
    1.59 +    : mpl::if_<
    1.60 +          is_array<T>,
    1.61 +          ptr_container_detail::array_deleter<T>,
    1.62 +          ptr_container_detail::scalar_deleter<T>
    1.63 +      >::type
    1.64 +{ 
    1.65 +    default_deleter() { }
    1.66 +    template<typename TT>
    1.67 +    default_deleter(default_deleter<TT> tt) { }
    1.68 +};
    1.69 +
    1.70 +} } } // End namespaces ptr_container_detail, move_ptrs, boost.
    1.71 +
    1.72 +#endif // #ifndef BOOST_MOVE_PTR_DEFAULT_DELETER_HPP_INCLUDED