Extend the call site default argument expansion mechanism?

Yuxuan Shui yshuiv7 at gmail.com
Thu May 10 14:33:59 UTC 2018


On Thursday, 10 May 2018 at 14:28:39 UTC, JN wrote:
> On Thursday, 10 May 2018 at 14:15:18 UTC, Yuxuan Shui wrote:
>> [...]
>
> For things like this you can use the OOP Factory pattern, 
> pseudocode:
>
> class DataStructureFactory
> {
>   this(Allocator alloc)
>   {
>     this.alloc = alloc;
>   }
>
>   Allocator alloc;
>
>   DataStructure createDataStructure(...)
>   {
>     return new DataStructure(..., alloc)
>   }
> }
>
> DataStructureFactory factory = new DataStructureFactory(new 
> SomeAllocator())
> auto data1 = factory.createDataStructure(...)
> auto data2 = factory.createDataStructure(...)
> auto data3 = factory.createDataStructure(...)

But doing it with default argument expansion saves you 1 
allocation, has 1 less type, while being just as readable. I 
think that's a win.


More information about the Digitalmars-d mailing list