epoc32/include/stdapis/boost/shared_array.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/shared_array.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,177 @@
     1.4 +#ifndef BOOST_SHARED_ARRAY_HPP_INCLUDED
     1.5 +#define BOOST_SHARED_ARRAY_HPP_INCLUDED
     1.6 +
     1.7 +//
     1.8 +//  shared_array.hpp
     1.9 +//
    1.10 +//  (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
    1.11 +//  Copyright (c) 2001, 2002 Peter Dimov
    1.12 +//
    1.13 +//  Distributed under the Boost Software License, Version 1.0. (See
    1.14 +//  accompanying file LICENSE_1_0.txt or copy at
    1.15 +//  http://www.boost.org/LICENSE_1_0.txt)
    1.16 +//
    1.17 +//  See http://www.boost.org/libs/smart_ptr/shared_array.htm for documentation.
    1.18 +//
    1.19 +
    1.20 +#include <boost/config.hpp>   // for broken compiler workarounds
    1.21 +
    1.22 +#if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
    1.23 +#include <boost/detail/shared_array_nmt.hpp>
    1.24 +#else
    1.25 +
    1.26 +#include <memory>             // TR1 cyclic inclusion fix
    1.27 +
    1.28 +#include <boost/assert.hpp>
    1.29 +#include <boost/checked_delete.hpp>
    1.30 +
    1.31 +#include <boost/detail/shared_count.hpp>
    1.32 +#include <boost/detail/workaround.hpp>
    1.33 +
    1.34 +#include <cstddef>            // for std::ptrdiff_t
    1.35 +#include <algorithm>          // for std::swap
    1.36 +#include <functional>         // for std::less
    1.37 +
    1.38 +namespace boost
    1.39 +{
    1.40 +
    1.41 +//
    1.42 +//  shared_array
    1.43 +//
    1.44 +//  shared_array extends shared_ptr to arrays.
    1.45 +//  The array pointed to is deleted when the last shared_array pointing to it
    1.46 +//  is destroyed or reset.
    1.47 +//
    1.48 +
    1.49 +template<class T> class shared_array
    1.50 +{
    1.51 +private:
    1.52 +
    1.53 +    // Borland 5.5.1 specific workarounds
    1.54 +    typedef checked_array_deleter<T> deleter;
    1.55 +    typedef shared_array<T> this_type;
    1.56 +
    1.57 +public:
    1.58 +
    1.59 +    typedef T element_type;
    1.60 +
    1.61 +    explicit shared_array(T * p = 0): px(p), pn(p, deleter())
    1.62 +    {
    1.63 +    }
    1.64 +
    1.65 +    //
    1.66 +    // Requirements: D's copy constructor must not throw
    1.67 +    //
    1.68 +    // shared_array will release p by calling d(p)
    1.69 +    //
    1.70 +
    1.71 +    template<class D> shared_array(T * p, D d): px(p), pn(p, d)
    1.72 +    {
    1.73 +    }
    1.74 +
    1.75 +//  generated copy constructor, assignment, destructor are fine
    1.76 +
    1.77 +    void reset(T * p = 0)
    1.78 +    {
    1.79 +        BOOST_ASSERT(p == 0 || p != px);
    1.80 +        this_type(p).swap(*this);
    1.81 +    }
    1.82 +
    1.83 +    template <class D> void reset(T * p, D d)
    1.84 +    {
    1.85 +        this_type(p, d).swap(*this);
    1.86 +    }
    1.87 +
    1.88 +    T & operator[] (std::ptrdiff_t i) const // never throws
    1.89 +    {
    1.90 +        BOOST_ASSERT(px != 0);
    1.91 +        BOOST_ASSERT(i >= 0);
    1.92 +        return px[i];
    1.93 +    }
    1.94 +    
    1.95 +    T * get() const // never throws
    1.96 +    {
    1.97 +        return px;
    1.98 +    }
    1.99 +
   1.100 +    // implicit conversion to "bool"
   1.101 +
   1.102 +#if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530)
   1.103 +
   1.104 +    operator bool () const
   1.105 +    {
   1.106 +        return px != 0;
   1.107 +    }
   1.108 +
   1.109 +#elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
   1.110 +    typedef T * (this_type::*unspecified_bool_type)() const;
   1.111 +    
   1.112 +    operator unspecified_bool_type() const // never throws
   1.113 +    {
   1.114 +        return px == 0? 0: &this_type::get;
   1.115 +    }
   1.116 +
   1.117 +#else 
   1.118 +
   1.119 +    typedef T * this_type::*unspecified_bool_type;
   1.120 +
   1.121 +    operator unspecified_bool_type() const // never throws
   1.122 +    {
   1.123 +        return px == 0? 0: &this_type::px;
   1.124 +    }
   1.125 +
   1.126 +#endif
   1.127 +
   1.128 +    bool operator! () const // never throws
   1.129 +    {
   1.130 +        return px == 0;
   1.131 +    }
   1.132 +
   1.133 +    bool unique() const // never throws
   1.134 +    {
   1.135 +        return pn.unique();
   1.136 +    }
   1.137 +
   1.138 +    long use_count() const // never throws
   1.139 +    {
   1.140 +        return pn.use_count();
   1.141 +    }
   1.142 +
   1.143 +    void swap(shared_array<T> & other) // never throws
   1.144 +    {
   1.145 +        std::swap(px, other.px);
   1.146 +        pn.swap(other.pn);
   1.147 +    }
   1.148 +
   1.149 +private:
   1.150 +
   1.151 +    T * px;                     // contained pointer
   1.152 +    detail::shared_count pn;    // reference counter
   1.153 +
   1.154 +};  // shared_array
   1.155 +
   1.156 +template<class T> inline bool operator==(shared_array<T> const & a, shared_array<T> const & b) // never throws
   1.157 +{
   1.158 +    return a.get() == b.get();
   1.159 +}
   1.160 +
   1.161 +template<class T> inline bool operator!=(shared_array<T> const & a, shared_array<T> const & b) // never throws
   1.162 +{
   1.163 +    return a.get() != b.get();
   1.164 +}
   1.165 +
   1.166 +template<class T> inline bool operator<(shared_array<T> const & a, shared_array<T> const & b) // never throws
   1.167 +{
   1.168 +    return std::less<T*>()(a.get(), b.get());
   1.169 +}
   1.170 +
   1.171 +template<class T> void swap(shared_array<T> & a, shared_array<T> & b) // never throws
   1.172 +{
   1.173 +    a.swap(b);
   1.174 +}
   1.175 +
   1.176 +} // namespace boost
   1.177 +
   1.178 +#endif  // #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
   1.179 +
   1.180 +#endif  // #ifndef BOOST_SHARED_ARRAY_HPP_INCLUDED