core.stdc.stdlib._compare_fp_t and qsort

Joe jma at freedomcircle.com
Sun Mar 18 11:29:47 UTC 2018


On Monday, 12 March 2018 at 03:50:42 UTC, Joe wrote:
> On Monday, 12 March 2018 at 03:13:08 UTC, Seb wrote:
>> Out of interest: I wonder what's your usecase for using qsort. 
>> Or in other words: why you can't use the high-level 
>> std.algorithm.sorting.sort?
>
> This is only temporary. I will be using 
> std.algorithm.sorting.sort. I was converting a C program and it 
> annoyed me that I couldn't get the qsort invocation past the D 
> compiler.

Now that I'm trying to use std.algorithm.sorting, I'm again 
puzzled by what I need to use for the "less" predicate. My first 
try was:

    sort!((a, b) => to!string((*a).name) < 
to!string((*b).name))(recs);

This results in the error:

Error: template std.algorithm.sorting.sort cannot deduce function 
from argument types !((a, b) => to!string((*a).name) < 
to!string((*b).name))(Record*[10]), candidates are:
/usr/lib/ldc/x86_64-linux-gnu/include/d/std/algorithm/sorting.d(1851):        std.algorithm.sorting.sort(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable, Range)(Range r) if ((ss == SwapStrategy.unstable && (hasSwappableElements!Range || hasAssignableElements!Range) || ss != SwapStrategy.unstable && hasAssignableElements!Range) && isRandomAccessRange!Range && hasSlicing!Range && hasLength!Range)

which is not very helpful. It's a bit different from the "no 
function match" that Adam complains about, but I presume it's 
because now we're dealing with templates, and although the 
compiler finds a single candidate, it's not satisfactory but it 
can't tell the user anything further.

I've tried using fromStringz((*x).name.ptr) instead of to!string 
(I'm still unclear to what extent can templates be used within 
templates).  I also tried using an explicit cast(Record *)x 
because I'm also unsure that type information is passed down.  
Neither change helped.


More information about the Digitalmars-d-learn mailing list