void main()
{
import std.stdio;
"Hello D".toHexString.writeln;
}
struct HexString
{
int i;
auto nibbleSplit()
{
auto MSB = i >> 4;
auto LSB = i & 15;
return [MSB, LSB];
}
}
auto toHexString(string str)
{
struct Hex { int i;
auto nibbleSplit() {
auto MSB = i >> 4;
auto LSB = i & 15;
return [MSB, LSB];
}
}
import std.algorithm : map;
import std.conv, std.range : join;
return str.map!Hex//String
.map!(e => e.nibbleSplit).join
.map!(n => n += n > 9 ? '7' : '0')
.map!(c => c.to!char);
}
Why doesn't the function compile? But the code is compiled with the HexString structure. The error given by the compiler is as follows:
>/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/iteration.d(582): Error: cannot access frame pointer of onlineapp.toHexString.Hex
/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/iteration.d(479): Error: template instance std.algorithm.iteration.MapResult!(Hex, string)
error instantiating
onlineapp.d(33): instantiated from here: map!string
onlineapp.d(34): Error: template onlineapp.toHexString.map!((e) => e.nibbleSplit).map
is not callable using argument types !()(MapResult!(Hex, string))
/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/iteration.d(446): Candidate is: map(Range)(Range r)
with Range = MapResult!(Hex, string)
must satisfy the following constraint:
` isInputRange!(Unqual!Range)