Weird const behavior

Simón Oroño sron611 at gmail.com
Thu Dec 20 01:37:59 UTC 2018


I have the following piece of code:


``````````````````````
#!/bin/env dub
/+ dub.sdl:
     name: day2
+/
import std.algorithm.iteration : group;
import std.stdio;

void main() {
     const auto a = group("simon");
     auto b = group("simon");
     writeln(a == b);
     writeln();
     writeln(a);
     writeln();
     writeln(b);
}
``````````````````````

When I run it, it gives me this output:

``````````````````````
true

const(Group!("a == b", string))("imon", Tuple!(dchar, uint)('s', 
1))

[Tuple!(dchar, uint)('s', 1), Tuple!(dchar, uint)('i', 1), 
Tuple!(dchar, uint)('m', 1), Tuple!(dchar, uint)('o', 1), 
Tuple!(dchar, uint)('n', 1)]
``````````````````````

The only difference (code-wise) is the `const` keyword. I've 
tried with both `ldc` and `dmd` with same result. Why is the 
output different when the variable is `const`?


More information about the Digitalmars-d-learn mailing list