Boost logo

Boost :

From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2003-01-08 15:28:44


----- Original Message -----
From: "Dirk Gerrits" <dirk_at_[hidden]>
To: "Boost mailing list" <boost_at_[hidden]>
Sent: Wednesday, January 08, 2003 6:15 PM
Subject: [boost] Re: intrusive tagging allows omision of unneeded headers

> Thorsten Ottosen wrote:
> [snip]
> > class X
> > {
> > public:
> > class tag {};
> > typedef tag X_tag;
> ^^^^^^^^^^^^^^^^^
> > };
> >
> > class bar
> > {
> > public:
> > class tag {};
> > typedef tag bar_tag;
> ^^^^^^^^^^^^^^^^^^^
> > };
>
> Why these typedefs? Why would one write X::X_tag instead of X::tag for
> example?

how can we specifiy that we want to specialize for a particular class
otherwise? Only by establising a convetion
that all (involved) classes have a unique typedef can we destinguish the
classes. For example

template< typename C >
void foo_impl( const C& c, typename C::bar_tag )
{
    cout << "bar specialised version" << endl;
}

will only be a candidate when C actually has a typedef bar_tag. due to
SFINAE the instantiation is allowed
to fail for classes that does not have a bar_tag typdef. And because the
above foo_impl is more specialized
than

template< typename C, typename Tag >
void foo_impl( const C& c, Tag t )
{
    cout << "default version" << endl;
}

the first foo_impl will be chosen as a better match.

regards

Thorsten


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