Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-09-04 08:36:18


----- Original Message -----
From: David Abrahams <david.abrahams_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, September 04, 2001 12:41 AM
Subject: Re: [boost] Documenting non-copyable-ness (was: Re: Review:
Boost.Threads)

>
> > I'll take this opportunity to ask this question:
> > Why isn't noncopyable a template class?
> >
> > That is:
> >
> > template<class T>
> > class noncopyable
> > {
> > protected:
> > noncopyable(){}
> > ~noncopyable(){}
> > private: // emphasize the following members are private
> > noncopyable( const noncopyable& );
> > const noncopyable& operator=( const noncopyable& );
> > }; // noncopyable
> >
> >
> > Used as:
> >
> > struct Some : boost::noncopyable< Some>
> > {
> > ...
> > };
> >
> > just wonder...
>
> Because it doesn't need to be a template class.
>
Well, then I am not being clear.

The current concern is that every noncopyable class is rooted at
'noncopyable', that is, a *single* and *uniquely identified* class:
noncopyable.

Consider:

class Foo : noncopyable {} ;
class Bar : noncopyable {} ;

Those two classes are *completely unrelated*, yet they belong to the same
hierarchy.
This fact -the conceptually wrong hierarchical relation between them- is
messy and a very subtle source of problems; even though most applications
will hide this.

Messy because in a graphical class browser everything is rooted at
noncopyable.
Error prone (very subtle) because, as it was expressed, one can manage both
classes through a noncopyable*.

Now, suppose noncopyable is a template class. Even though noncopyable itself
dosen't use the template parameter, instances of noncopyable<T> and
noncopyable<U> are different classes as long as T and U are different types.
This propery is what we need to solve this problem:

class Foo : noncopyable<Foo> {} ;
class Bar : noncopyable<Bar> {} ;

Now, Foo and Bar are not rooted at the same class since noncopyable<Foo> and
noncopyable<Bar> are distinct classes, yet they inherited *individualy* the
required semantics.

I call classes like noncopyable a 'semanticer', and what I presented here is
a known general idiom to aggregate semanticers to a given class: class T :
semanticer<T> {}.
This idiom is guaranteed to work becuase semanticer<T> is guaranteed to be
as unique as T, so you get the semantic without the price of over
inheritance.

Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com

> -Dave
>
>
> Info: http://www.boost.org Unsubscribe:
<mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>


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