|
Boost : |
From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-02-18 15:06:48
On Monday 18 February 2002 02:09 pm, you wrote:
[snip]
> Tagging types can be totally done with traits classes.
> The key of this proposal is that tags defined this way participate in
> overload resolution, much like base classes does, except that unlike base
> classes they are used to sort out types in the last phase instead of the
> first.
> Their main purpose is to resolve ambiguities and to group specializations.
>
> template<class GPoint T> double distance ( T const& lhs, T const& rhs ) ;
> // won't clash with std::distance
As I see it, tags provide a way to control when a template type parameter can
be bound to a particular type. This, I believe, is an extremely important
ability and in some form it should be supported in C++0x. However, if tags
are semantically equivalent to traits, why the new name and syntax?
If I were to counter-propose something along these lines, I would propose
that template parameters can optionally be followed by a restriction of the
form:
IF '(' expression ')'
template parameters may only be bound to types such that 'expression'
evaluates true. Just to compare on your example, the following declaration
using tags:
template<class GPoint T> double distance ( T const& lhs, T const& rhs ) ;
would be written:
template<class T if (is_gpoint<T>::value)>
double distance ( T const& lhs, T const& rhs ) ;
I personally would prefer that the extension be formulated in this way
because:
1) it's a pure extension, that will not break any existing code
2) it builds on existing knowledge and implementations of traits
3) it allows arbitrary expressions to determine binding (perhaps tags can
do this also?)
4) it's utterly trivial to implement
Doug
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk