Safer casts
Dee Girl
deegirl at noreply.com
Sat May 10 11:32:11 PDT 2008
Sean Kelly Wrote:
> == Quote from Dee Girl (deegirl at noreply.com)'s article
> > What are good examples that show Tango is a good example of designing with a new D mindset?
>
> I'm somewhat biased since I created the module, but I'd consider tango.core.Array
> to be a good example of a D-oriented mindset. It's an array-specific algorithm
> module intended to leverage the D slice syntax for range speficication. For exmaple:
>
> import tango.core.Array;
> import tango.stdc.stdio;
>
> void main()
> {
> int[] buf = [1,6,2,5,9,2,3,2,4].dup;
>
> // calls Array.sort with optional predicate
> buf[0 .. 3].sort( (int x, int y) { reuturn x < y; } );
> assert( buf[0 .. 3] == [1,2,5,6]);
> buf.sort(); // full sort of buf with default predicate
> // below is equivalent to equal_range in C++
> printf( "there are %d 2s in buf\n",
> buf[buf.lbound(2) .. buf.ubound(2)].length );
> // more fun stuff
> printf( "there are %d 5s between index 2 and 6\n",
> buf[2 .. 6].count( 5 ) );
> }
>
> etc. (I'm using printf for the sake of illustration, not because
> I suggest you actually use it in your app)
>
>
> Sean
Nice example! How did you do it? Did Tango change the compiler and added more methods to arrays? Thank you, Dee Girl
More information about the Digitalmars-d
mailing list