const and immutable values, D vs C++?
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Wed Dec 4 14:44:43 UTC 2019
When is there a noticable difference when using const values
instead of immutable values in a function body? And when should
immutable be used instead of const?
f(){
const x = g();
immutable y = g();
... do stuff with x and y …
}
I'm comparing D to C++ and I get the following mapping:
D:
enum constant = number
C++:
enum : decltype(number) { constant = number }
D:
auto p = g()
C++:
auto p = g()
D:
const p = g()
C++:
const auto p = g()
D:
immutable p = g()
C++:
hmmm...
Has anyone done a feature by feature comparison with C++? It
would be interesting to see what it looks like.
More information about the Digitalmars-d-learn
mailing list