On Tue, May 06, 2014 at 12:28:19AM +0000, bearophile via Digitalmars-d wrote:
> Andrei Alexandrescu:
> 
> >So I'm looking at creation functions and in particular creation
> >functions for arrays.
> >
> >1. Follow the new int[n] convention:
> >
> >auto a = allok.make!(int[])(42);
> >assert(a.length == 42);
> >assert(a.equal(repeat(0, 42));
> >
> >2. Follow the [ literal ] convention:
> >
> >auto a = allok.make!(int[])(42);
> >assert(a.length == 1);
> >assert(a[0] == 42);
> 
> Both cases are needed. Unfortunately we don't have named arguments in
> D, otherwise you can use the same name for both operations, using
> different arguments.
[...]

Adam's trick with a Length struct neatly solves this problem. :-)

        struct Length { size_t n; }
        auto a = allok.make!(int[])(Length(42), 1);
        ... // etc

It's a very clever idea, and I like it!


T

-- 
In theory, software is implemented according to the design that has been 
carefully worked out beforehand. In practice, design documents are written 
after the fact to describe the sorry mess that has gone on before.
  • API Andrei Alexandrescu via Digitalmars-d
    • Re: API Adam D. Ruppe via Digitalmars-d
      • Re: API Adam D. Ruppe via Digitalmars-d
        • Re: API bearophile via Digitalmars-d
          • Re: API Adam D. Ruppe via Digitalmars-d
            • Re: API bearophile via Digitalmars-d
              • Re: API Adam D. Ruppe via Digitalmars-d
      • Re: API Orvid King via Digitalmars-d
    • Re: API bearophile via Digitalmars-d
      • Re: API H. S. Teoh via Digitalmars-d
    • Re: API Brian Schott via Digitalmars-d
    • Re: API Walter Bright via Digitalmars-d
      • Re: API MattCoder via Digitalmars-d
      • Re: API Andrei Alexandrescu via Digitalmars-d
        • Re: API Walter Bright via Digitalmars-d
          • Re: API Andrei Alexandrescu via Digitalmars-d
          • Re: API monarch_dodra via Digitalmars-d
    • Re: API Idan Arye via Digitalmars-d
    • Re: API Brad Anderson via Digitalmars-d
      • Re: API bearophile via Digitalmars-d

Reply via email to