January 30, 2015 Re: Arrays, garbage collection | ||||
---|---|---|---|---|
| ||||
Posted in reply to Foo | On 1/30/15 1:29 AM, Foo wrote:
>
> @nogc
> @safe
> T[n] s(T = Args[0], size_t n = Args.length, Args...)(auto ref Args args)
> pure nothrow {
> return [args];
> }
>
> @nogc
> @safe
> T[n] s(T, size_t n)(auto ref T[n] values) pure nothrow {
> return values;
> }
>
> void main() {
> pragma(msg, typeof(s(1, 2, 3)));
> pragma(msg, typeof([1, 2, 3].s));
> }
> ----
>
> Compilation output:
> int[3]
> int[3]
>
> You only have to type a dot between the array and the 's'.
> Because of pure and nothrow and the low cost of the function call even
> such a lousy thing like the DMD optimizer should be capable of inlining
> such a function every time.
Thanks for this code, it's a lot nicer and simpler than mine. -- Andrei
|
January 30, 2015 Re: Arrays, garbage collection | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 1/30/2015 6:54 AM, Andrei Alexandrescu wrote:
> On 1/30/15 1:29 AM, Foo wrote:
> Thanks for this code, it's a lot nicer and simpler than mine. -- Andrei
I'm going to swipe this for an upcoming presentation I'm doing. Thanks, Foo!
|
January 30, 2015 Re: Arrays, garbage collection | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Friday, 30 January 2015 at 22:21:15 UTC, Walter Bright wrote:
> On 1/30/2015 6:54 AM, Andrei Alexandrescu wrote:
>> On 1/30/15 1:29 AM, Foo wrote:
>> Thanks for this code, it's a lot nicer and simpler than mine. -- Andrei
>
>
> I'm going to swipe this for an upcoming presentation I'm doing. Thanks, Foo!
My pleasure.
|
January 31, 2015 Re: Arrays, garbage collection | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | > Thanks for this code, it's a lot nicer and simpler than mine. -- Andrei
So, pull request for std.array and reverting the dollar thingie?
Problem solved?
|
January 31, 2015 Re: Arrays, garbage collection | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin Nowak | On 1/31/15 1:10 AM, Martin Nowak wrote:
>> Thanks for this code, it's a lot nicer and simpler than mine. -- Andrei
>
> So, pull request for std.array and reverting the dollar thingie?
> Problem solved?
This looks like the way to go. I apologize to the community for the indecision shown. -- Andrei
|
January 31, 2015 Re: Arrays, garbage collection | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 1/31/2015 8:08 AM, Andrei Alexandrescu wrote:
> On 1/31/15 1:10 AM, Martin Nowak wrote:
>>> Thanks for this code, it's a lot nicer and simpler than mine. -- Andrei
>>
>> So, pull request for std.array and reverting the dollar thingie?
>> Problem solved?
>
> This looks like the way to go. I apologize to the community for the indecision
> shown. -- Andrei
I'm on board with this, too.
|
Copyright © 1999-2021 by the D Language Foundation