|
Boost : |
From: Dietmar Kuehl (dietmar_kuehl_at_[hidden])
Date: 2000-08-11 08:24:52
Hi,
--- jsiek_at_[hidden] wrote:
> I agree. The templated guard class is fine for implementation, but it
> shouldn't be hard coded into the concept requirements, hence the
> nested typedef. One reason for this is that we don't want to add
> lock()/unlock() expressions to the Mutex concept. If those functions
> exist, users will gravitate towards them instead of using the guard.
That is, basically we would define something like this:
template <typename Mutex>
struct lock {
lock(Mutex& m): m_mutex(m) { m_mutex.do_lock(); }
~lock() { m_mutex.do_unlock(); }
// ...
private:
Mutex& m_mutex;
};
struct mutex {
typedef ::lock<mutex> lock;
friend class lock;
// ...
private:
void do_lock();
void do_unlock();
};
This allows the use of a generic "lock" class which does not have to be
reimplemented all the time and at the same time prevents users from
even thinking about using the functions manually. Of course,
applicability of the "lock" class defines a new concept, say
"AutoLockable", basically consisting of the applicability of
'do_lock()'
and 'do_unlock()' through the class 'lock<Mutex>' (where 'Mutex' is the
class realizing the concept).
=====
<mailto:dietmar_kuehl_at_[hidden]>
<http://www.dietmar-kuehl.de/>
__________________________________________________
Do You Yahoo!?
Kick off your party with Yahoo! Invites.
http://invites.yahoo.com/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk