From slices to perfect imitators: opByValue

Michel Fortin via Digitalmars-d digitalmars-d at puremagic.com
Thu May 8 03:14:17 PDT 2014


On 2014-05-08 03:58:21 +0000, Andrei Alexandrescu 
<SeeWebsiteForEmail at erdani.org> said:

> So there's this recent discussion about making T[] be refcounted if and 
> only if T has a destructor.
> 
> That's an interesting idea. More generally, there's the notion that 
> making user-defined types as powerful as built-in types is a Good 
> Thing(tm).
> 
> ...
> 
> This magic of T[] is something that custom ranges can't avail 
> themselves of. In order to bring about parity, we'd need to introduce 
> opByValue which (if present) would be automatically called whenever the 
> object is passed by value into a function.

Will this solve the problem that const(MyRange!(const T)) is a 
different type from const(MyRange!(T))? I doubt it. But they should be 
the same type if we want to follow the semantics of the language's 
slices, where const(const(T)[]) is the same as const(T[]).

Perhaps this is an orthogonal issue, but I wonder whether a solution to 
the above problem could make opByValue unnecessary.

-- 
Michel Fortin
michel.fortin at michelf.ca
http://michelf.ca



More information about the Digitalmars-d mailing list