difficulties with const structs and alias this / template functions
    Dennis 
    dkorpel at gmail.com
       
    Mon Nov 19 00:50:28 UTC 2018
    
    
  
On Sunday, 18 November 2018 at 22:30:52 UTC, Rubn wrote:
> Yah most people tend to avoid const for this reason. It only 
> really works for basic types, if you have a "const int" you can 
> convert it to an "int" by copy. But if you have a type like 
> Vector!(const int) that won't work, you can't even convert 
> Vector!int to Vector!(const int) easily for example.
That's unfortunate. I can relate better to Jonathan's article [1] 
now. But I'll still try to make it working with const since other 
people might want to use it.
I'm also trying to make it work with immutable, and from BigInt 
[2] I learned that constructors need to be `pure` for creating 
immutable objects. (I don't know why.)
Are there any other gotchas? I didn't add an immutable variant 
for toQ32 like Stanislav suggested, but creating an immutable q32 
from a q16 still seems to work fine.
[1] http://jmdavisprog.com/articles/why-const-sucks.html
[2] https://issues.dlang.org/show_bug.cgi?id=17330
    
    
More information about the Digitalmars-d-learn
mailing list