Is there any real reason to use "const"?
rempas
rempas at tutanota.com
Tue Jan 25 08:34:05 UTC 2022
On Monday, 24 January 2022 at 19:15:42 UTC, Steven Schveighoffer
wrote:
>
> I know exactly what you were doing:
>
> ```d
> void mul_num(T)(T num) {
> num *= 2;
> }
> ```
>
> That will fail if you just do `mul_num(number)` because
> templates infer the type from the argument (e.g. T becomes
> `const int`)
>
> Unfortunately, D doesn't have a "tail-const" modifier, which
> would work really well here.
>
> -Steve
Yeah right, now I remember! I did it about 2 months ago in a
template function that converts types and It didn't compiled.
Now, I know why, thank you!
More information about the Digitalmars-d
mailing list