digitalmars.D.learn - split Error - no overload matches
- forkit (17/17) Feb 14 2022 This code will not compile.
- ag0aep6g (3/8) Feb 14 2022 "isWhite" is ambiguous. There's std.uni.isWhite and std.ascii.isWhite.
- forkit (7/16) Feb 14 2022 thanks.
- Steven Schveighoffer (30/50) Feb 15 2022 I'm kind of surprised more doesn't come out. Typically when a template
- meta (11/11) Feb 15 2022 A trick i use often:
- H. S. Teoh (5/20) Feb 16 2022 +1, noice! I should use this more often.
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
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
On Monday, 14 February 2022 at 11:37:38 UTC, ag0aep6g wrote:On 14.02.22 12:14, forkit wrote: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'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
On 2/14/22 5:18 PM, forkit wrote:On Monday, 14 February 2022 at 11:37:38 UTC, ag0aep6g wrote: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. -SteveOn 14.02.22 12:14, forkit wrote: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'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 15 2022
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
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