Safer casts

Bill Baxter dnewsgroup at billbaxter.com
Tue May 13 13:05:30 PDT 2008


Sean Kelly wrote:
> == Quote from Don (nospam at nospam.com.au)'s article
>> Sean Kelly wrote:
>>> Janice Caron wrote:
>>>> 2008/5/13 Sean Kelly <sean at invisibleduck.org>:
>>>>>  It depends what you mean by "powerful."  Passing a comparator as a
>>>>> template parameter,
>>>>>  as with sort!(), means that the choice of comparator must be made at
>>>>> compile-time rather
>>>>>  than run-time.  This may be problematic in some instances.
>>>> I think you meant to say, the choice of comparator /may/ be made at
>>>> compile-time. Not must.
>>>>
>>>>     sort!(compare)(array); // compile time
>>>>     sort(compare, array); // run time
>>> I meant the way sort works in std.algorithm.  But it appears that my
>>> answer was D 1.0-specific.  I had no idea D 2.0 added the option to
>>> instantiate a template on an alias to a local variable.
>> It should work in D1.0, as well. It was added not long before D1.00 came
>> out.
> 
> It doesn't.  Or more specifically, this doesn't work in D 1.0:
> 
>     void sort(alias cmp, T)( T buf )
>     {
>         // pretend we're sorting
>         cmp( buf[0], buf[1] );
>     }
> 
>     void doSort( int[] buf, bool delegate(int,int) cmp )
>     {
>         sort!(cmp)( buf );
>     }
> 
> 
> Sean

Oh, *that's* what you guys are talking about?  Here's the bugzilla bug 
for it:

http://d.puremagic.com/issues/show_bug.cgi?id=493

--bb



More information about the Digitalmars-d mailing list