Deduction regression or improvement?

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Tue Mar 8 15:54:00 PST 2016


On Tue, Mar 08, 2016 at 11:31:54PM +0000, Johan Engelen via Digitalmars-d wrote:
> On Tuesday, 8 March 2016 at 22:35:57 UTC, H. S. Teoh wrote:
> >On Tue, Mar 08, 2016 at 09:22:35PM +0000, Johan Engelen via Digitalmars-d
> >wrote:
> >>Hi all,
> >>  Should the following compile or not?
> >>
> >>auto foo(T)(T start, T end) {}
> >>void main() {
> >>    const SomeStruct a;
> >>    SomeStruct b;
> >>    foo(a,b);
> >>}
[...]
> >IMO, this *should* compile and infer T == const(SomeStruct) as the
> >common type of a and b.  But I'm not sure whether or not this is a
> >regression.
> 
> What was surprising to me is that 2.068.2 deduces T = SomeStruct. But
> SomeStruct c = a;
> works fine, i.e. copying const(SomeStruct) to a SomeStruct is fine.
> Argument passing a struct is just copying, so should be fine to deduce
> T=SomeStruct?
[...]

Hmm. I guess it makes sense if SomeStruct has no indirections, since
structs are value types so you can always copy a const value to a
mutable variable / parameter.


T

-- 
It is of the new things that men tire --- of fashions and proposals and improvements and change. It is the old things that startle and intoxicate. It is the old things that are young. -- G.K. Chesterton


More information about the Digitalmars-d mailing list