Ticket #1113: shared_array.patch

File shared_array.patch, 1.5 KB (added by Nathan Crookston <nathan.crookston@…>, 13 years ago)
  • shared_array.hpp

     
    3535namespace boost
    3636{
    3737
     38namespace detail
     39{
     40  template <class T> struct sa_wrap {};
     41
     42  //is T a const-qualified version of Y?
     43  template< class T, class Y > struct is_const_version_impl
     44  {
     45    typedef char (&yes) [1];
     46    typedef char (&no)  [2];
     47
     48    static yes f( const sa_wrap<Y const>& );
     49    static no  f( ... );
     50
     51    enum _vt { value = sizeof( f( sa_wrap<T>() ) ) == sizeof(yes) };
     52  };
     53
     54  struct sa_empty {};
     55
     56  template <bool> struct sa_is_const;
     57
     58  template <> struct sa_is_const<true>
     59  {
     60    typedef sa_empty type;
     61  };
     62
     63  template <> struct sa_is_const<false>
     64  {};
     65
     66  template <class T, class Y>
     67  struct sa_enable
     68    : public sa_is_const<is_const_version_impl<T, Y>::value>
     69  {};
     70}
     71
    3872//
    3973//  shared_array
    4074//
     
    69103    {
    70104    }
    71105
    72 //  generated copy constructor, assignment, destructor are fine
     106//  generated assignment, destructor are fine
    73107
     108    template <class Y>
     109    shared_array(shared_array<Y> const & other,
     110        typename detail::sa_enable<T, Y>::type = detail::sa_empty()) // never throws
     111      : px(other.px),
     112        pn(other.pn)
     113    {}
     114
    74115    void reset(T * p = 0)
    75116    {
    76117        BOOST_ASSERT(p == 0 || p != px);
     
    115156
    116157private:
    117158
     159    template <class Y> friend class shared_array;
     160
    118161    T * px;                     // contained pointer
    119162    detail::shared_count pn;    // reference counter
    120163