Segfault using std.algorithm.map

klickverbot see at klickverbot.at
Sat Oct 16 13:24:00 PDT 2010


On 10/16/10 10:13 PM, klickverbot wrote:
> ---
> import std.algorithm;
> import std.stdio;
>
> enum INPUT = "cqrb lryqna rb fjh, fjh qjamna cqjw axc cqracnnw. qnan,
> hxd wnena twxf qxf oja cx bqroc! xq kh cqn fjh, cqn jwbfna rb
> mnjmvjwblqnbc.";
>
> void main() {
> foreach ( offset; 0..25 ) {
> writeln( map!( ( dchar c ) {
> if ( c < 'a' ) return c;
> if ( 'z' < c ) return c;
> return cast( dchar )( ( ( ( c - 'a' ) + offset ) % 26 ) + 'a' );
> } )( INPUT ) );
> }
> }
> ---

Okay, after experimenting for a bit, I found that this works:

       writeln( map!( ( c ){
          return offset;
       } )( INPUT ) );

While this segfaults:

       writeln( map!( ( c ){
          return cast( dchar )( offset );
       } )( INPUT ) );

I guess this should go to bugzilla, right?


More information about the Digitalmars-d-learn mailing list