Boost logo

Boost Users :

Subject: Re: [Boost-users] [non Boost] Template troubles.
From: Noah Roberts (roberts.noah_at_[hidden])
Date: 2008-12-12 12:52:45


Noah Roberts wrote:

> In int const x[5][5], the int contained within the dual array is the
> constant. In the case of T const& value[] though it is T that is const,
> which is an array. This is nonsense I believe (arrays are always
> r-values). VS seems to have no way to handle it while the others do.

I think this is a bug in VS.

At first I thought that what I was doing and what you are doing where
different because you had a typedef int[size][size] that you later
declare a const object of. I thought maybe this actually made the
*array* const but I was mistaken. The standard quite clearly states,
with example, that even when you are doing that to a typedef of array
type...the const applies to the elements, not to the array. The
provided example from 8.3.4/1:

typedef int A[5], AA[2][3];
typedef const A CA; // type is "array of 5 const int"
typedef const AA CAA; // type is "array of 2 array of 3 const int"

It doesn't get less ambiguous than that.

That means, to me, that even when T is an array type, expecting a const
reference of that type should resolve in the same manner and your
template should resolve. As someone mentioned in comp.lang.c++ your
second version (the one expecting an array) is a closer match and should
be the one used.

I think there's a bug in msvc in template typing. I'd bet that it's
considering const T (&ref)[size] to be an /array of const array of int/
when passed an /array of array of const int/, which is nonsense in C++
and would never resolve to anything.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net