uniform initialization in D (as in C++11): i{...}

Timothee Cour via Digitalmars-d digitalmars-d at puremagic.com
Mon Apr 4 22:44:38 PDT 2016


typo:
q{...} // comment (existing syntax)
=>
q{...} // string literal (existing syntax)

On Mon, Apr 4, 2016 at 10:39 PM, Timothee Cour <thelastmammoth at gmail.com> wrote:
> what's D's answer for C++11's uniform initialization [1] which allows DRY code?
>
> Could we have this:
> ----
> struct A{
>   int a;
>   int b;
> }
>
> A fun(A a, int b) {
>   if(b==1) return i{0,1};
>   else if(b==2) return i{2,3};
>   else return fun(i{3,4}, 1);
> }
> ----
>
> As for which syntax to use, that's an orthogonal question, but here I
> used i{} since {} (from C++11) is already used by delegates (with
> tuples also being discussed at some point, which didn't pan out bc
> someone mentioned it was ambiguous in some case; see my next email
> proposal below though [2])
>
> ----
> {} // delegate (existing syntax)
> q{...} // comment (existing syntax)
> i{...} // uniform intialization (proposed syntax)
> t{...} // tuple(a,b) (proposed syntax)
> T{...} // TypeTuple!(a,b) (proposed syntax)
> ----
>
> [1] http://programmers.stackexchange.com/questions/133688/is-c11-uniform-initialization-a-replacement-for-the-old-style-syntax
> [2] EMAIL:proposed syntax for tuple: t{} and TypeTuple: T{}


More information about the Digitalmars-d mailing list