Sort! string[][]

Brian Myers bmyers at harryanddavid.com
Wed Apr 23 13:42:44 PDT 2008


Brian Myers Wrote:

> The sort! template in std.algorithm doesn't seem to work. The following code:
> 
> import std.string;
> import std.algorithm;
> 
> void main(char[][] args)
> {
>     string[] words = ["c", "ab", "bb"];
>     sort!("a < b", SortStrategy.stable)(words);
>     assert(words == ["ab", "bb", "c"]);
> }
> 
> This code gives the following error:
> 
> C:\Documents and Settings\dag033\D\d_dedup>dmd -g hello.d
> hello.d(10): template std.algorithm.sort(alias less,SwapStrategy ss = SwapStrategy.unstable,alias iterSwap = .iterSwap,R
> ange) does not match any function template declaration
> hello.d(10): template std.algorithm.sort(alias less,SwapStrategy ss = SwapStrategy.unstable,alias iterSwap = .iterSwap,R
> ange) cannot deduce template function from argument types !("a < b",int)(invariant(char)[][])
> 
> I must admit I really haven't wrapped my head around the way templates work yet. I certainly get the over all idea, but the subtleties of type deduction and instantiation still elude me in non-trivial cases. What's going on here?
> 
> Brian
> 

Andrei Alexandrescu just responded noting that I was using SortStrategy instead of SwapStrategy as I should have been. He's filing a bug for the misleading error message.

Thanx Andrei.

Brian




More information about the Digitalmars-d mailing list