epoc32/include/stdapis/boost/ptr_container/detail/static_move_ptr.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/static_move_ptr.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,212 @@
     1.4 +// (C) Copyright Thorsten Ottosen 2005.
     1.5 +// (C) Copyright Jonathan Turkanis 2004.
     1.6 +// (C) Copyright Daniel Wallin 2004.
     1.7 +// Distributed under the Boost Software License, Version 1.0. (See accompanying
     1.8 +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
     1.9 +
    1.10 +// Implementation of the move_ptr from the "Move Proposal" 
    1.11 +// (http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2002/n1377.htm) 
    1.12 +// enhanced to support custom deleters and safe boolean conversions.
    1.13 +//
    1.14 +// The implementation is based on an implementation by Daniel Wallin, at
    1.15 +// "http://aspn.activestate.com/ASPN/Mail/Message/Attachments/boost/
    1.16 +// 400DC271.1060903@student.umu.se/move_ptr.hpp". The current was adapted 
    1.17 +// by Jonathan Turkanis to incorporating ideas of Howard Hinnant and 
    1.18 +// Rani Sharoni. 
    1.19 +
    1.20 +#ifndef BOOST_STATIC_MOVE_PTR_HPP_INCLUDED
    1.21 +#define BOOST_STATIC_MOVE_PTR_HPP_INCLUDED
    1.22 +
    1.23 +#include <boost/config.hpp> // Member template friends, put size_t in std.
    1.24 +#include <algorithm>        // swap.
    1.25 +#include <cstddef>          // size_t
    1.26 +#include <boost/compressed_pair.hpp> 
    1.27 +#include <boost/ptr_container/detail/default_deleter.hpp>       
    1.28 +#include <boost/ptr_container/detail/is_convertible.hpp>       
    1.29 +#include <boost/ptr_container/detail/move.hpp>       
    1.30 +#include <boost/static_assert.hpp>
    1.31 +#include <boost/type_traits/add_reference.hpp>
    1.32 +#include <boost/type_traits/is_array.hpp>
    1.33 +
    1.34 +#if defined(BOOST_MSVC)
    1.35 +#pragma warning(push)
    1.36 +#pragma warning(disable:4521)        // Multiple copy constuctors.
    1.37 +#endif
    1.38 +
    1.39 +namespace boost { namespace ptr_container_detail {
    1.40 +
    1.41 +    
    1.42 +template< typename T, 
    1.43 +          typename Deleter = 
    1.44 +              move_ptrs::default_deleter<T> >
    1.45 +class static_move_ptr 
    1.46 +{
    1.47 +public:
    1.48 +
    1.49 +    typedef typename remove_bounds<T>::type             element_type;
    1.50 +    typedef Deleter                                     deleter_type;
    1.51 +
    1.52 +private:
    1.53 +    
    1.54 +    struct safe_bool_helper { int x; };
    1.55 +    typedef int safe_bool_helper::* safe_bool;
    1.56 +    typedef boost::compressed_pair<element_type*, Deleter> impl_type;
    1.57 +
    1.58 +public:
    1.59 +    typedef typename impl_type::second_reference        deleter_reference;
    1.60 +    typedef typename impl_type::second_const_reference  deleter_const_reference;
    1.61 +
    1.62 +        // Constructors
    1.63 +
    1.64 +    static_move_ptr() : impl_(0) { }
    1.65 +
    1.66 +    static_move_ptr(const static_move_ptr& p)
    1.67 +        : impl_(p.get(), p.get_deleter())    
    1.68 +        { 
    1.69 +            const_cast<static_move_ptr&>(p).release();
    1.70 +        }
    1.71 +
    1.72 +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))    
    1.73 +    static_move_ptr( const move_ptrs::move_source<static_move_ptr<T,Deleter> >& src )
    1.74 +#else
    1.75 +    static_move_ptr( const move_ptrs::move_source<static_move_ptr>& src )
    1.76 +#endif    
    1.77 +            : impl_(src.ptr().get(), src.ptr().get_deleter())
    1.78 +            {
    1.79 +                src.ptr().release();
    1.80 +            }
    1.81 +    
    1.82 +    template<typename TT>
    1.83 +    explicit static_move_ptr(TT* tt) 
    1.84 +        : impl_(tt, Deleter()) 
    1.85 +        { }
    1.86 +
    1.87 +        // Destructor
    1.88 +
    1.89 +    ~static_move_ptr() { if (ptr()) get_deleter()(ptr()); }
    1.90 +
    1.91 +        // Assignment
    1.92 +
    1.93 +    static_move_ptr& operator=(static_move_ptr rhs)
    1.94 +        {
    1.95 +            rhs.swap(*this);
    1.96 +            return *this;
    1.97 +        }
    1.98 +
    1.99 +        // Smart pointer interface
   1.100 +
   1.101 +    element_type* get() const { return ptr(); }
   1.102 +
   1.103 +    element_type& operator*() 
   1.104 +        { 
   1.105 +            /*BOOST_STATIC_ASSERT(!is_array);*/ return *ptr(); 
   1.106 +        }
   1.107 +
   1.108 +    const element_type& operator*() const 
   1.109 +        { 
   1.110 +            /*BOOST_STATIC_ASSERT(!is_array);*/ return *ptr(); 
   1.111 +        }
   1.112 +
   1.113 +    element_type* operator->()  
   1.114 +        { 
   1.115 +            /*BOOST_STATIC_ASSERT(!is_array);*/ return ptr(); 
   1.116 +        }    
   1.117 +
   1.118 +    const element_type* operator->() const 
   1.119 +        { 
   1.120 +            /*BOOST_STATIC_ASSERT(!is_array);*/ return ptr(); 
   1.121 +        }    
   1.122 +
   1.123 +
   1.124 +    element_type* release()
   1.125 +        {
   1.126 +            element_type* result = ptr();
   1.127 +            ptr() = 0;
   1.128 +            return result;
   1.129 +        }
   1.130 +
   1.131 +    void reset()
   1.132 +        {
   1.133 +            if (ptr()) get_deleter()(ptr());
   1.134 +            ptr() = 0;
   1.135 +        }
   1.136 +
   1.137 +    template<typename TT>
   1.138 +    void reset(TT* tt) 
   1.139 +        {
   1.140 +            static_move_ptr(tt).swap(*this);
   1.141 +        }
   1.142 +
   1.143 +    template<typename TT, typename DD>
   1.144 +    void reset(TT* tt, DD dd) 
   1.145 +        {
   1.146 +            static_move_ptr(tt, dd).swap(*this);
   1.147 +        }
   1.148 +
   1.149 +    operator safe_bool() const { return ptr() ? &safe_bool_helper::x : 0; }
   1.150 +
   1.151 +    void swap(static_move_ptr& p) { impl_.swap(p.impl_); }
   1.152 +
   1.153 +    deleter_reference get_deleter() { return impl_.second(); }
   1.154 +
   1.155 +    deleter_const_reference get_deleter() const { return impl_.second(); }
   1.156 +private:
   1.157 +    template<typename TT, typename DD>
   1.158 +    void check(const static_move_ptr<TT, DD>& ptr)
   1.159 +        {
   1.160 +            typedef move_ptrs::is_smart_ptr_convertible<TT, T> convertible;
   1.161 +            BOOST_STATIC_ASSERT(convertible::value);
   1.162 +        }   
   1.163 +
   1.164 +#if defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) || defined(BOOST_NO_SFINAE)
   1.165 +// give up on this behavior
   1.166 +#else 
   1.167 +
   1.168 +    template<typename Ptr> struct cant_move_from_const;
   1.169 +
   1.170 +    template<typename TT, typename DD> 
   1.171 +    struct cant_move_from_const< const static_move_ptr<TT, DD> > { 
   1.172 +        typedef typename static_move_ptr<TT, DD>::error type; 
   1.173 +    };
   1.174 +
   1.175 +    template<typename Ptr> 
   1.176 +    static_move_ptr(Ptr&, typename cant_move_from_const<Ptr>::type = 0);
   1.177 +
   1.178 +
   1.179 +public:
   1.180 +    static_move_ptr(static_move_ptr&);
   1.181 +
   1.182 +    
   1.183 +private:
   1.184 +    template<typename TT, typename DD>
   1.185 +    static_move_ptr( static_move_ptr<TT, DD>&,
   1.186 +                     typename 
   1.187 +                     move_ptrs::enable_if_convertible<
   1.188 +                         TT, T, static_move_ptr&
   1.189 +                     >::type::type* = 0 );
   1.190 +
   1.191 +#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING || BOOST_NO_SFINAE
   1.192 +
   1.193 +//#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
   1.194 +//    template<typename TT, typename DD>
   1.195 +//    friend class static_move_ptr;
   1.196 +//#else
   1.197 +    public:
   1.198 +//#endif
   1.199 +    typename impl_type::first_reference 
   1.200 +    ptr() { return impl_.first(); } 
   1.201 +
   1.202 +    typename impl_type::first_const_reference 
   1.203 +    ptr() const { return impl_.first(); }
   1.204 +
   1.205 +    impl_type impl_;
   1.206 +};
   1.207 +
   1.208 +} // namespace ptr_container_detail
   1.209 +} // End namespace boost.
   1.210 +
   1.211 +#if defined(BOOST_MSVC)
   1.212 +#pragma warning(pop) // #pragma warning(disable:4251)
   1.213 +#endif
   1.214 +
   1.215 +#endif      // #ifndef BOOST_STATIC_MOVE_PTR_HPP_INCLUDED