D needs...

Daniel Kozák via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Mon May 11 06:09:15 PDT 2015


On Mon, 11 May 2015 12:24:34 +0000
weaselcat via Digitalmars-d-announce
<digitalmars-d-announce at puremagic.com> wrote:

> On Monday, 11 May 2015 at 12:22:34 UTC, Dennis Ritchie wrote:
> > On Monday, 11 May 2015 at 11:59:02 UTC, Namespace wrote:
> >> Inspired by ponce idioms list for D I've set up something 
> >> similar.
> >> There are some themes in D which come up regulary and are 
> >> discussed to the vomit. If something is agreed, it gets 
> >> forgotten sometimes and the theme disappears into oblivion 
> >> (for a few months :P). To prevent this, I've collected some 
> >> hot-discussed themes, their history and their current state. I 
> >> hope this helps to avoid unnecessary discussions in the future 
> >> and finally cut off these issues (either with an official 
> >> decision "Nope, keep as it is" or with an implementation).
> >>
> >> I've tried to stay as objective as possible, but if something 
> >> seems to be too subjective, please let me know, so I can fix 
> >> it.
> >>
> >> http://dgame.github.io/dneeds/
> >
> > Thanks. Many programmers find fault with this problem:
> >
> > "No problem. But if you have more elements it could be annoying 
> > to count them. That's why some D users wanted that the compiler 
> > does that for them.
> >
> > int[$] c = [1, 2, 3]; // the compiler detects the dollar and 
> > count the elements for us"
> 
> +1, I have to go review why this was removed. It's annoying that 
> I have to manually count static arrays.

import std.stdio;

@safe @property auto static_array()
{
    static struct _static_array
    {
        @safe
        @property
        T[n] s(T, size_t n)(auto ref T[n] values) { return values; }
        
        T[0][n] opIndex(size_t n = T.length, T...)(T items)
        {
            typeof(return) arr;
            foreach (index,item; items)
                arr[index] = item;
            
            return (values) { return values; }(arr);//s!(T[0], n)(arr);
        }
    }

    return _static_array();
}

void main() {
    auto sa = static_array[4,5,7];
    writeln(sa);
}



More information about the Digitalmars-d-announce mailing list