Bug 16389 – "const" should be inferred for template methods

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-08-14T13:59:11Z
Last change time
2024-12-13T18:49:27Z
Assigned to
No Owner
Creator
Andrei Alexandrescu
Moved to GitHub: dmd#19169 →

Comments

Comment #0 by andrei — 2016-08-14T13:59:11Z
Currently defining const and non-const versions of methods in generic code is redundant and error-prone. When calling a non-const method against a const object, D should just generate the const method and attempt to typecheck it. This should cut down significantly on user code and aggravation.
Comment #1 by schveiguy — 2016-08-15T13:22:54Z
One can do this already, though I agree it would be nice if this was the default: struct S { int _x; int x(this T)() { return _x; } } void main() { S s; const S cs; writeln(s.x, cs.x); }
Comment #2 by greeenify — 2016-08-15T13:34:23Z
> Currently defining const and non-const versions of methods in generic code is redundant and error-prone. FWIW isn't inout a solution to a similar problem? In any case inout needs rebranding
Comment #3 by andrei — 2016-08-15T13:50:48Z
(In reply to greenify from comment #2) > > Currently defining const and non-const versions of methods in generic code is redundant and error-prone. > > FWIW isn't inout a solution to a similar problem? In any case inout needs > rebranding Deduction is different because there's no qualifier applied if the method is never used on a const object.
Comment #4 by robert.schadek — 2024-12-13T18:49:27Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19169 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB