Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-02-18 14:09:11

----- Original Message -----
From: "Mac Murrett" <mmurrett_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Monday, February 18, 2002 2:50 PM
Subject: Re: [boost] Most needed/desired features in C++

> Herb, other Boosters,
> On Monday, February 18, 2002, at 03:11 AM, Herb Sutter wrote:
> > Pardon if this has already been discussed on the list, but I'd
> > like your
> > feedback on this question: "What are the most needed or desired
> > features in
> > C++ for modern library writing in general and Boost in particular?"
> [snip]
> > What else should be on the list?
> I would love to be able to specify an archetype for my template
> parameters. For example:
> template<assignable T>
> class vector
> {
> ...
> };
> The compiler then can generate an error on vector<auto_ptr<int> >
> that makes sense.
> This would solve most of the common complaints that novices have
> when learning to use templates.
> Mac Murrett.
I've thinking about this for quite some time. I'm not quite sure if this
facility can be well defined, but as far I could elaborate it, it would be
something like this:

The idea is to allow lookup rules and overload resolutions to additionally
use "tagnames". And of course, a way to externally "tag" concrete and
parameterized types:

// The following "tag definition" tags each typename in the enclosed block
with a "tagname"
// All types inside the tag definition should be previously defined (forward
decl are not allowed inside tag definitions).

tag GPoint // 'GPoint' is a tagname.
  Windows::POINT ;
  MyPoint ;
  template<class> Point ; // This is assuming a sort of implicit typedef

// The template argument list syntax can be extended to allow a "tag

template<class GPoint T>
void foo ( T const & ) ;

template<class GPoint T> class PointOperations { ... } ;

A tag modifier is used to exclude from the overload candidate list typenames
not tagged with the specific tag.

This would combine with the typeof()/reflection features discussed to allow
checking if a type is tagged in some way:


A type could have any number of tags.

tag WindowsSpecific
  Windows::POINT ;

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
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

tag input_iterator_tag { template<class T> std::vector<T>::iterator ; }
tag output_iterator_tag { template<class T> std::back_insert_iterator<
std::vector<T>::iterator > ; }

template<class input_iterator_tag T> struct Some {} ;

template<> struct Some<output_iterator_tag> {} ;

Here, the specialization parameter is not a typename but a tagname.
tagnames are not typenames, so this would require specializations to allow
tagnames along with typenames. Lookup rules will match every typename which
is correspondingly tagged. (partial ordering relations should be defined in
this case; I leave that for further discussions).

Well, following Dietmar advice, I will eventually try to formalize this to
see if it is really well defined, useful and won't break any existing
program. In the meantime, I leave it here for your disection.

Fernando Cacciola
Sierra s.r.l.

Boost list run by bdawes at, gregod at, cpdaniel at, john at