Static arrays, typeof and IFTI?
Norbert Nemec
Norbert at Nemec-online.de
Tue Oct 11 14:21:20 PDT 2011
On 11.10.2011 15:35, Andrei Alexandrescu wrote:
> On 10/11/11 2:56 AM, bearophile wrote:
>> Since years some people (among them there is me too) are asking for
>> this syntax:
>>
>> int arr[$] = [1,2,3,4];
>>
>> Vote for it here (an enhancement request from 2006!):
>> http://d.puremagic.com/issues/show_bug.cgi?id=481
>
> I was more enthused about that, but later I realized there are very few
> situations in which one reasonably has a fixed-size array that is large
> enough to make counting inadequate and is also updated often enough to
> make the feature worthwhile. It's one of those features that are nice to
> have but are not really missed in real code.
How about function templates? You can start overloading like
void f(int[1] x);
void f(int[2] x);
void f(int[3] x);
but there is no way to do it via a single template. The only way to do
it would be explicit instantiation
void f(int N)(int[N] x);
to be called as
f!(3)([1,2,3]);
Of course, this can always be done, but to me it seems ugly enough to
think about a solution.
More information about the Digitalmars-d
mailing list