Collections question

Jakob Ovrum via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 27 23:12:29 PST 2015


On Friday, 27 November 2015 at 20:14:21 UTC, Andrei Alexandrescu 
wrote:
> There's some experience in various libraries with both 
> approaches. Which would you prefer?

Well, I think we should recognize that they're the same thing but 
with different names. I don't have a strong preference for 
either, but I think the opCall approach might invite questions 
like "why is T t; different from auto t = T(); with this 
collection type?".

The current container library's `make` function has a neat 
feature (well, I'm biased here) where the element type doesn't 
have to be specified when construction arguments are provided:

auto arr = make!Array(1, 2, 3); // element type inferred to be 
`int`
auto arr = make!Array([42]); // Also for range construction

Naturally this doesn't work with nullary construction, but I 
think it's worth mentioning because this is not nearly as 
practical with static member functions. Of course the current 
model is not usable as-is because `make` uses an ugly hack when 
"making" empty struct containers.



More information about the Digitalmars-d mailing list