Re: Elements of constant array as constant expressions.
"Marsh J. Ray" wrote:
[..]
Array initializers, even for const arrays, don't seem to have nearly
the constraints constraints as those for template type arguments. I
just tested this on one compiler (MSVC80), but I don't think this is
any vendor-specific extension.
But how is that related to the case when certain things _can_ be
treated as compile-time constants?
Consider what the compiler would have to do to instantiate your
template given the following:
int salesman_optimal_route_distance()
{
return 0; /* TODO: exercise for reader */
}
int const array[] = { salesman_optimal_route_distance() };
Why would that demonstrate anything except that it's allowed? Try
adding
const int rtc = salesman_optimal_route_distance();
Is that a compile-time constant? No. Try
const int ctc = 42;
Is that a compile-time constant? Yes. What conclusions should we
derive from that?
template<int I>
struct A
{ };
int main()
{
A<array[0]> a;
And change this to
A<rtc> aa;
What do you make of that?
A<ctc> aaa; // should work just fine
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]