While studying Ali's book at chapter "Constructor and Other
Special Functions" and the below code snippet:
import std.stdio;
struct S {
this(int i) { writeln("an object"); }
// Original
//this(int i) const { writeln("a const object"); }
//this(int i) immutable { writeln("an immutable object");
}
//this(int i) shared { writeln("a shared object"); }
const this(int i) { writeln("a const object"); }
immutable this(int i) { writeln("an immutable object"); }
shared this(int i) { writeln("a shared object"); }
}
void main() {
auto m = S(1);
auto c = const(S)(2);
auto i = immutable(S)(3);
auto s = shared(S)(4);
}
Assuming I can speak in correct programmer-ese: I was wondering
why the qualifiers were placed after the function parameter list
(int i). Just for fun, I moved to type qualifiers before the
function definitions "this" (like a return type?) and the output
was exactly identical. So I guess my question is, is this just
a matter of esthetics or is some more nuanced goal at work here?