Boost logo

Boost :

From: Gabriel Dos Reis (Gabriel.Dos-Reis_at_[hidden])
Date: 1999-12-16 23:21:24


scleary_at_[hidden] writes:

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

No, I don't think so. You are confusing 'template-parameter' with
'template-argument'. The paragraph you're quoting applies to
non-type template-parameter as evidenced by the full context. For the
sake of clarity, here is the context:

14.1/4

  A non-type template-parameter shall have one of the following
  (optionally cv-qualified) types:
  --- integral or enumeration type,
  --- pointer to object or pointer to function,
  --- reference to object or reference to function,
  --- pointer to member.

The Standards goes on saying:

14.1/5

  [Note: other types are disallowed either explicitly below or
  implicitly by the rules governing the form of template-arguments
  (14.3). ] The top-level cv-qualifiers of the template-parameter are
  ignored when determining its type.

Note that only a non-type template-parameter may have a type.
[ Types aren't (yet) first class objects in C++. ]

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

Did yours?

The paragraph you're quoting doesn't apply. 'int' and 'const int'
are distinct template-arguments; furthermore X<int> and <const int>
are distinct class types.

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

No, 'const int' isn't a *fundamnetal* type.

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

All these issues about sub-namespace segragation make me wonder whether
Boost wouldn't end up with more namespaces than useful libraries ;-)

-- Gaby


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