Boost logo

Boost :

From: scleary_at_[hidden]
Date: 1999-12-16 10:20:35


> From: John Maddock [mailto:John_Maddock_at_[hidden]]
> . . . However I do not believe that cv-qualified types are the same
> as the unqualified types:
>
> . . .
>
> This approach is also consistent with existing traits classes
> - such as numeric_limits, char_traits, and iterator_traits, which are
> not generally specialised on cv-qualified types - for example
numeric_limits<const
> int>::is_specialized is false.
>

I've been doing some research into the Standard to see if the following is
legal:

template <class T> struct X { };
template <> struct X<int> { };
template <> struct X<const int> { };
X<const int> bob;

And I have to conclude that it is NOT legal, for the following reason:

ANSI 14.1p5 ". . .The top-level cv-qualifiers on the template-parameter are
ignored when determining its type."

The above code will result in ambiguity -- the compiler _should_ choke on
whether to use "X<int>" or "X<const int>".

Also, this means "numeric_limits<const int>::is_specialized" is _true_.

If we really want to differentiate cv-ness (IMHO, not necessary), we can:
namespace currently_under_discussion {
template <class T> struct is_const_helper;
template <class T> struct is_const_helper<T &>
{ static const bool value = false; };
template <class T> struct is_const_helper<const T &>
{ static const bool value = true; };
} // namespace currently_under_discussion
template <class T> struct is_const
{ static const bool value = currently_under_discussion::is_const_helper<T
&>::value; };

which I think will work.

        -Steve


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