Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-02-18 16:36:16


On Monday 18 February 2002 03:48 pm, you wrote:
> Consider a "tag expression" to be the expression that is used to rule out a
> given candidate type during matching.
> In my proposal, a tag expression was simply a tagname, where the equality
> test was implicitly used, but tagnames could be made to participate in
> complex expressions too, so (3) is not a reason to prefer traits instead of
> true tags.

Okay, we're converging then. I wasn't sure if you had considered the notion
of "tag expressions" as well.

> In order for this to be really useful, 'tag expressions' should be allowed
> to be used for specializations too.
> Following your syntax, this would look something like:
>
> template<class T> struct Some {} ;
>
> template<class T> struct Some< is_output_iterator_tag<T>::value > {} ;
>
> But this doesn't fit properly into current C++. Something else would be
> needed here.

I have more questions than answers for this. In your original message, you
had the following (I added the #1 and #2):

template<class input_iterator_tag T> struct Some {} ; // #1

template<> struct Some<output_iterator_tag> {} ; // #2

I'm assuming that #1 is used for any type T that has the tag
'input_iterator_tag', and #2 is used for any type T that has the tag
'output_iterator_tag'? If so, then why isn't #2 written as:

template<class output_iterator_tag T> struct Some {}; // #2?

I ask because #2 looks like a full specialization, but it is actually a class
template. Even if tags are in a different namespace from types (as they would
have to be), I believe such a construct would cause confusion.

For reference, I would write the equivalent to the above as:

template<typename T> struct Some; // undefined

template<typename T if (is_input_iterator_tag<T>::value)>
struct Some { }; // #1

template<typename T if (is_output_iterator_tag<T>::value)>
struct Some { }; // #2

Multiple primary class templates? Yes, but I think the idea of a 'primary
template' is misguided anyway once one considers restrictions on the binding
of arguments to parameters. Think function overloading: there is no notion of
a 'primary function' but there are parameter/argument binding restrictions.

In any case, it appears (to me) that the two approaches are roughly
equivalent in all but syntax. On the syntax front, I believe that minimal is
better: introducing additional keywords and namespaces into the language will
complicate it considerably, and is bound to run into a great deal of
resistance.

        Doug


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