Boost logo

Boost :

From: Mark Rodgers (mark.rodgers_at_[hidden])
Date: 2000-08-11 01:47:12

From: "Kevlin Henney" <kevlin_at_[hidden]>
> There is no reason for the scoped guard class to be nested: this reduces
> the (re)usabilty of such classes. The scoped guard class I have in mind
> is external and templated on anything that is lockable. This has the
> benefit of (1) being more generic and (2) reduces the code required to
> write a synchronised class.

That may be a convenient implementation of the guard for some synchronised
objects; others might have different implementation requirements. Thus
we might see

  struct YourMutex {
     typedef boost::lock_implementation<YourMutex> lock;


  struct MyMutex {
     class lock { /* something else */ };

User's wouldn't need to care. They'd just write

    YourMutex::lock x(ym);
    MyMutex::lock y(mm);

I don't suppose it's any more flexible than your alternative (I could
always specialise the lock template for MyMutex), but it fits in
nicely with how we use containers and iterators, i.e.,

    std::list<int>::iterator i
    std::iterator< std::list<int> > i;

Consistency is important IMHO.


Boost list run by bdawes at, gregod at, cpdaniel at, john at