Thread overview
split Error - no overload matches
Feb 14, 2022
forkit
Feb 14, 2022
ag0aep6g
Feb 14, 2022
forkit
Feb 15, 2022
meta
Feb 16, 2022
H. S. Teoh
February 14, 2022
This code will not compile.

Error: no overload matches for `split`

However, if I uncomment the //import std.uni : isWhite;

then it will compile.

I don't understand. I thought 'import std;' would be sufficient here??

//  ----

module test;
@safe:

import std;

void main()
{
    //import std.uni : isWhite; // need to uncomment this for it to compile.
    writeln("Learning D is fun".split!isWhite);
}

// -------
February 14, 2022
On 14.02.22 12:14, forkit wrote:
> However, if I uncomment the //import std.uni : isWhite;
> 
> then it will compile.
> 
> I don't understand. I thought 'import std;' would be sufficient here??

"isWhite" is ambiguous. There's std.uni.isWhite and std.ascii.isWhite. `import std;` can't know which one you want.
February 14, 2022
On Monday, 14 February 2022 at 11:37:38 UTC, ag0aep6g wrote:
> On 14.02.22 12:14, forkit wrote:
>> However, if I uncomment the //import std.uni : isWhite;
>> 
>> then it will compile.
>> 
>> I don't understand. I thought 'import std;' would be sufficient here??
>
> "isWhite" is ambiguous. There's std.uni.isWhite and std.ascii.isWhite. `import std;` can't know which one you want.

thanks.

a little more help from the compiler itself would also have been appreciated ;-)

e.g:

Error: The call to isWhite is ambiguous between the following methods: 'std.uni.isWhite' and 'std.ascii.isWhite'
February 15, 2022

On 2/14/22 5:18 PM, forkit wrote:

>

On Monday, 14 February 2022 at 11:37:38 UTC, ag0aep6g wrote:

>

On 14.02.22 12:14, forkit wrote:

>

However, if I uncomment the //import std.uni : isWhite;

then it will compile.

I don't understand. I thought 'import std;' would be sufficient here??

"isWhite" is ambiguous. There's std.uni.isWhite and std.ascii.isWhite. import std; can't know which one you want.

thanks.

a little more help from the compiler itself would also have been appreciated ;-)

e.g:

Error: The call to isWhite is ambiguous between the following methods: 'std.uni.isWhite' and 'std.ascii.isWhite'

I'm kind of surprised more doesn't come out. Typically when a template doesn't match, it explains why it doesn't match. But for this case, it's not explaining anything.

First, the reason it doesn't match is due to D's limitations on how to match against "things that might compile". The definition for split that should accept this is:

auto split(alias isTerminator, Range)(Range range)
if (isForwardRange!Range && is(typeof(unaryFun!isTerminator(range.front))))

That second check is testing to see if it compiles, and if it doesn't for any reason, then it doesn't match.

Now, the symbol isWhite is an overload set, which is in error (ambiguous). So I'm not sure how to test this better.

Note, if I copy the entire definition of split locally, it explains the problem correctly (though still not as clear as it could be):

onlineapp.d(19): Error: template `test.split` cannot deduce function from argument types `!(isWhite)(string)`
onlineapp.d(6):        Candidate is: `split(alias isTerminator, Range)(Range range)`
  with `isTerminator = isWhite,
       Range = string`
  must satisfy the following constraint:
`       is(typeof(unaryFun!isTerminator(range.front)))`

And finally, I will note that split/splitter by default without any parameters splits on whitespace if that is your goal.

-Steve

February 15, 2022

A trick i use often:

import std;

void main()
{
    import uni =  std.uni;
    writeln("Learning D is fun".split!(uni.isWhite));
}

Under-rated way of importing things, you don't bloat your scope anymore

February 16, 2022
On Tue, Feb 15, 2022 at 06:37:44PM +0000, meta via Digitalmars-d-learn wrote:
> A trick i use often:
> 
> ```D
> import std;
> 
> void main()
> {
>     import uni =  std.uni;
>     writeln("Learning D is fun".split!(uni.isWhite));
> }
> 
> ```
> 
> Under-rated way of importing things, you don't bloat your scope anymore

+1, noice!  I should use this more often.


T

-- 
Truth, Sir, is a cow which will give [skeptics] no more milk, and so they are gone to milk the bull. -- Sam. Johnson