Re: Elements of constant array as constant expressions.
"Marsh J. Ray" wrote:
Victor Bazarov wrote:
"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?
Maybe you can prove that it can be treated as a compile-time constant,
but can you construct a rule which allows what you are asking and show
the standards committee that the implementers across an incredible
range of platforms can teach their compilers to be able to prove that
it can be treated as a compile-time constant?
Just add 'elements of an array of const' to the list of what a constant
expression "can involve" (in 5.19/1):
"An integral constant-expression can involve only literals (2.13),
enumerators, const variables, elements of arrays of const, or static
data members of integral or enumeration types initialized with
constant expressions (8.5), ..."
Also, don't forget that your array may have externally-visible
linkage.
How is linkage playing into that now?
<skip>
What do you make of that?
What I make of it is that the standards committee didn't want to
require a compiler to have the entire content of (possibly large)
arrays available at the time of template instantiation.
This just doesn't make sense. What is so different between elements
of an array of const int and a single const it? If the compiler can
determine that a single int variable can be used in a compile-time
constant expression, there is nothing seriously more difficult to do
that for any element of an array. The Committee just didn't think of
it, most likely. Let's hear from somebody on the Committee, shall we?
V
---
[ 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 ]