[Issue 24688] Parameter by-value keeps const (only in templates)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 19 13:02:04 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24688

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305 at gmail.com
         Resolution|---                         |WONTFIX

--- Comment #3 from RazvanN <razvan.nitu1305 at gmail.com> ---
What you are asking for is not a reasonable strategy. The type deduction
mechanism works by looking at the parameter type and binding T to 'const int'.
It's an elegant and simple to understand strategy. If you want tpl to be
instantiated with a mutable parameter you can just specify that at the call
site: 
`z = tpl!int(i);`.

Having the compiler deduce constraints from the template body (or worse: just
guess) is something that will complicate the implementation of the compiler and
it's gonna be a behavior that is hard to understand (it's not intuitive). There
will be a lot of gotcha moments for users when they have to guess what was the
type with which the compiler instantiated the template.

--


More information about the Digitalmars-d-bugs mailing list