Boost logo

Glas :

Re: [glas] glas Digest, Vol 25, Issue 1

From: Karl Meerbergen (Karl.Meerbergen_at_[hidden])
Date: 2007-04-06 05:00:22

Hi Robert,

Thanks for the suggestion. I already had this in mind for the traits
classes, but I could consider this too for the free functions indeed.

However, 'default' function implementations are not (yet) allowed in
Concept C++, so, therefore I would only do this for typedefs (i.e. traits).


Robert P. Goddard wrote:

>I'm generally supportive of your idea of using free functions and traits
>in place of member functions and member typedefs. However, I caution
>against doing away with the latter. The Standard Library provides a good
>example (as it often does): The default definition for
>std::iterator_traits is, in part,
>template <class Iterator>
>struct iterator_traits {
> typedef typename Iterator::value_type value_type;
>That way the developer of an iterator has a choice: Provide a
>specialization of iterator_traits, or provide a nested typedef and let
>the default iterator_traits pick it up. The latter is often easier, in
>part because nested typedefs can come from a base class. The former is
>sometimes necessary, such as non-class types or classes developed by
>someone else.
>The same principle applies to free functions versus member functions: A
>reasonable default definition of size() could be
>template <class V>
>VectorExpression<V>::size_type size( const V& size )
> return V.size();
>Again, the developer of a new VectorExpression class has a choice:
>Overload the free size() function or provide a member function. The
>latter is often preferred, e.g. when it's a virtual function, and the
>former is sometimes necessary, e.g. when it's a non-class or you don't
>own it.
>In both cases, the free version is the preferred interface for users.
>The member version is provided primarily for developers, who can be the
>same users wearing different hats.