www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - split Error - no overload matches

reply forkit <forkit gmail.com> writes:
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);
}

// -------
Feb 14 2022
parent reply ag0aep6g <anonymous example.com> writes:
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.
Feb 14 2022
parent reply forkit <forkit gmail.com> writes:
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'
Feb 14 2022
parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
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: ```d 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
Feb 15 2022
parent reply meta <meta gmail.com> writes:
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
Feb 15 2022
parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
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
Feb 16 2022