Compile-Time std::map

Jari-Matti Mäkelä jmjmak at utu.fi.invalid
Sat Apr 28 04:56:32 PDT 2007


NN wrote:
> Jari-Matti Mäkelä Wrote:
>> NN wrote:
>> > I allways wanted to create std::map but in compile time.
>> > 
>> > The problem:
>> > I want to write smth like:
>> > int[int] x = {3:3,2:2,1:1}
>> > 
>> > But compiler will generate the following:
>> > int[int] x = {1:1,2:2,3:3}
>> > 
>> > Thus I can use binary search on x.
>> > 
>> > Is it possible to do in D ?
>> > Thanx.
>> 
>> Well, in case you didn't notice, DMD 1.014 now includes hash literals.
>> Assigning static hashes aren't yet supported directly, but you can do
>> simple cases like
>> 
>>   int val = ([1:11,2:22,3:33][1]);
>> 

> But it does not do what I want.
> I want to rearange the values in compile time.

Oh, sorry. If you just want to rearrange the array contents on compile time,
you can do it with a CTFE function or with tuples, then assign the
resulting tuple into an array.



More information about the Digitalmars-d mailing list