Correct use of map

Dfr deflexor at yandex.ru
Fri Jan 3 23:57:03 PST 2014


Thank you fo reply, i'm using DMD32 D Compiler v2.064
Tried to copy/paste your code and here is full message what it 
prints:

core.exception.AssertError at std.algorithm(1942): Assertion failure
----------------
t(_d_assertm+0x16) [0x807d326]
t() [0x808123a]
t(pure nothrow @trusted void 
std.algorithm.swap!(std.typecons.Tuple!(immutable(char)[], 
int).Tuple).swap(ref std.typecons.Tuple!(immutable(char)[], 
int).Tuple, ref std.typecons.Tuple!(immutable(char)[], 
int).Tuple)+0x59) [0x8079de1]
t(pure nothrow @safe void std.typecons.Tuple!(immutable(char)[], 
int).Tuple.opAssign!(std.typecons.Tuple!(immutable(char)[], 
int).Tuple).opAssign(std.typecons.Tuple!(immutable(char)[], 
int).Tuple)+0x3c) [0x807958c]
t(pure nothrow @safe void 
std.array.Appender!(std.typecons.Tuple!(immutable(char)[], 
int).Tuple[]).Appender.put!(std.typecons.Tuple!(immutable(char)[], 
int).Tuple).put(std.typecons.Tuple!(immutable(char)[], 
int).Tuple)+0x8e) [0x8079cde]
t(_D3std5array118__T5arrayTSmain90__T9MapResultS14main9__lambda1TS3std9algorithm19__T8splitterTAyaTaZ8splitterFAyaaZ6ResultZ9MapResultZ5arrayFSmain90__T9MapResultS14main9__lambda1TS3std9algorithm19__T8splitterTAyaTaZ8splitterFAyaaZ6ResultZ9MapResultZAS3std8typecons16__T5TupleTAyaTiZ5Tuple+0x46) 
[0x8079666]
t(_Dmain+0x50) [0x8074a20]
t(void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll().void __lambda1()+0x10) [0x807e5d8]
t(void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate())+0x18) 
[0x807e550]
t(void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll()+0x27) [0x807e59f]
t(void rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate())+0x18) 
[0x807e550]
t(_d_run_main+0x117) [0x807e4e7]
t(main+0x14) [0x807ab3c]
/lib/libc.so.6(__libc_start_main+0xf5) [0x45003865]
----------------



On Friday, 3 January 2014 at 20:07:34 UTC, bearophile wrote:
> Dfr:
>
>> Here is few code eaxamples, i don't know why it is doesn't 
>> work as expected.
>>
>> Here i want to transform string into list of tuples split by 
>> character:
>>
>> auto nameparts = splitter("go.home", '.').map!(v => 
>> tuple(v,0)).array;
>>
>> This gives me not very useful message about assert and stuff:
>> core.exception.AssertError at std.algorithm(1942): Assertion 
>> failure
>
> It works for me:
>
>
> void main() {
>     import std.stdio, std.algorithm, std.typecons, std.range;
>
>     auto nameParts = "go.home"
>                      .splitter('.')
>                      .map!(v => tuple(v, 0))
>                      .array;
>
>     nameParts.writeln;
> }
>
>
> Output:
>
> [Tuple!(string, int)("go", 0), Tuple!(string, int)("home", 0)]
>
> I am using dmd 2.065alpha on Windows.
>
> Bye,
> bearophile



More information about the Digitalmars-d-learn mailing list