Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-09-21 18:19:44


From: "Peter Dimov" <pdimov_at_[hidden]>

> Yes, this is the "official" scoped_ptr rationale, but note that foo can
> often be rewritten as
>
> T* foo(T* x, /* ... */)
> {
> T t;
> //
> // big, long, hairy, function
> // ...
> }
>
> and that big, long, hairy functions are problematic either way.

Even short, hairy functions can be weird. What's going on here?

  template<class T> shared_ptr<T> make_shared(weak_ptr<T> const & r) //
never throws
  {
    // optimization: avoid throw overhead
    if(r.use_count() == 0)
    {
        return shared_ptr<T>();
    }

    try
    {
        return shared_ptr<T>(r); // 1
    }
    catch(use_count_is_zero const &)
    {
        return shared_ptr<T>();
    }
  }

How will use_count_is_zero get thrown at "1"?
Oh, this is a thread-safety thing?
A comment would be a big help here...

How about getting rid of the complication in case of BOOST_NO_THREADS?

-----------------------------------------------------------
           David Abrahams * Boost Consulting
dave_at_[hidden] * http://www.boost-consulting.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk