January 26, 2007
Kevin Bealer wrote:
> Bill Baxter wrote:
>> Kevin Bealer wrote:
>>> Bill Baxter wrote:
>>>> Serg Kovrov wrote:
>>>>> Frits van Bommel wrote:
>>>>>> No, that's one of the big missing things.
>>>>>
>>>>> Exactly!
>>>>>
>>>>
>>>> Seems like with tuples now it might be possible to make a function that would do the trick:
>>>>
>>>> int[char[]] months = AA("Jan", 1, "Feb", 2, "Mar", 3);
>>>>
>>>> This could be another interesting challenge akin to Andrei's max() challenge.  Write a function that constructs an AA from it's arguments using the "best" types.
>>>>
>>>> For that matter it would be interesting to see a template which constructs an array using the best type to hold the arguments (as opposed to just the type of the first argument).
>>>>
>>>> --bb
>>>
>>> I don't know why all this syntax is needed; in particular, without the a.dup, it crashes.  I don't know why -- it might be a bug or just a bad assumption on my part.
>>
>> make it 'inout a', maybe?
>>
>> --bb
> 
> I haven't checked to see whether that works - but even if it does, I still don't see *why* it's more legal.
> 
> Kevin

Well it doesn't work.  You can't just say inout a, and since you don't know the type you can't use "inout Type a".
But looking at it again, I'm not sure why I thought that would work in the first place.

--bb

January 26, 2007
Kevin Bealer wrote:
> Bill Baxter wrote:
>> Kevin Bealer wrote:
>>> Bill Baxter wrote:
>>>> Serg Kovrov wrote:
>>>>> Frits van Bommel wrote:
>>>>>> No, that's one of the big missing things.
>>>>>
>>>>> Exactly!
>>>>>
>>>>
>>>> Seems like with tuples now it might be possible to make a function that would do the trick:
>>>>
>>>> int[char[]] months = AA("Jan", 1, "Feb", 2, "Mar", 3);
>>>>
>>>> This could be another interesting challenge akin to Andrei's max() challenge.  Write a function that constructs an AA from it's arguments using the "best" types.
>>>>
>>>> For that matter it would be interesting to see a template which constructs an array using the best type to hold the arguments (as opposed to just the type of the first argument).
>>>>
>>>> --bb
>>>
>>> I don't know why all this syntax is needed; in particular, without the a.dup, it crashes.  I don't know why -- it might be a bug or just a bad assumption on my part.
>>
>> make it 'inout a', maybe?
>>
>> --bb
> 
> I haven't checked to see whether that works - but even if it does, I still don't see *why* it's more legal.
> 
> Kevin

How about this, though:

    foreach(i, a; values) {
        static if ((i & 1) == 1) {
            rv[ values[i-1] ] = a;
        }
    }


Seems to work.

--bb
1 2
Next ›   Last »