const and immutable values, D vs C++?
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Thu Dec 5 12:05:57 UTC 2019
On Thursday, 5 December 2019 at 12:00:23 UTC, Ola Fosheim Grøstad
wrote:
> So basically, templated functions get flow-typing.
But it is not reliable :-(
struct node {int value; node* next;}
node n0 = {1,null};
node mk_node1()(node* n){
node tmp = {2019, n};
return tmp;
}
node mk_node2()(bool ok){
node tmp = {2019, ok ? null : &n0};
return tmp;
}
void main() {
immutable y = mk_node1(null); //succeeds
immutable x = mk_node2(true); //fails
}
More information about the Digitalmars-d-learn
mailing list