www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Voldemort Type Construction Error

reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
I've made progress at the helper findingSplitter at

https://github.com/nordlow/justd/blob/master/substitution.d#L122

I need this for implementing a new Phobos lazy `substitute()` (or 
replace).

I've done most logic (AFAICT in my head) but I can't make the 
call to Result() work as it fails as

substitution.d(187,18): Error: struct 
substitution.findingSplitter!("a == b", string, string, string, 
string).findingSplitter.Result cannot deduce function from 
argument types !()(string, string, string, string), candidates 
are:
substitution.d(126,12):        substitution.findingSplitter!("a 
== b", string, string, string, string).findingSplitter.Result()
substitution.d(194,32): Error: template instance 
substitution.findingSplitter!("a == b", string, string, string, 
string) error instantiating
substitution.d(196,12): Error: undefined identifier 'equal', did 
you mean alias 'Unqual'?
/home/per/Work/justd/traits_ex.d(64,13): Warning: statement is 
not reachable

What have I missed?
Jan 15
next sibling parent reply Anon <anon anon.anon> writes:
On Friday, 15 January 2016 at 14:04:50 UTC, Nordlöw wrote:
 What have I missed?
In line 126, `static struct Result()` is a template. Either drop the parens there, or change the call on line 187 to `Result!()(haystack, needles)`.
Jan 15
parent reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Friday, 15 January 2016 at 16:51:24 UTC, Anon wrote:
 On Friday, 15 January 2016 at 14:04:50 UTC, Nordlöw wrote:
 What have I missed?
In line 126, `static struct Result()` is a template. Either drop the parens there, or change the call on line 187 to `Result!()(haystack, needles)`.
Ahh, annoying mistake. Why is this allowed? /Per
Jan 15
parent reply Kapps <opantm2+spam gmail.com> writes:
On Friday, 15 January 2016 at 20:04:47 UTC, Nordlöw wrote:
 On Friday, 15 January 2016 at 16:51:24 UTC, Anon wrote:
 On Friday, 15 January 2016 at 14:04:50 UTC, Nordlöw wrote:
 What have I missed?
In line 126, `static struct Result()` is a template. Either drop the parens there, or change the call on line 187 to `Result!()(haystack, needles)`.
Ahh, annoying mistake. Why is this allowed? /Per
At least for functions, making them templates provides some benefits like inferring attributes. Not sure if it behaves the same way on structs by making all functions within it templates.
Jan 15
parent Jonathan M Davis via Digitalmars-d-learn writes:
On Saturday, January 16, 2016 06:06:03 Kapps via Digitalmars-d-learn wrote:
 On Friday, 15 January 2016 at 20:04:47 UTC, Nordlw wrote:
 On Friday, 15 January 2016 at 16:51:24 UTC, Anon wrote:
 On Friday, 15 January 2016 at 14:04:50 UTC, Nordlw wrote:
 What have I missed?
In line 126, `static struct Result()` is a template. Either drop the parens there, or change the call on line 187 to `Result!()(haystack, needles)`.
Ahh, annoying mistake. Why is this allowed? /Per
At least for functions, making them templates provides some benefits like inferring attributes. Not sure if it behaves the same way on structs by making all functions within it templates.
It does struct S() { void foo() { } } void main() safe { S!() s; s.foo(); } but having to do S!() for that rather than S is so ugly that I can't imagine anyone actually doing it, whereas it's actually useful for functions - particularly when you want to overload a templated function with one that takes no template arguments. You _can_ finally overload those with normal functions, but the overload rules don't work quite the same such that I would normally avoid overloading a templated function with a non-templated one. - Jonathan M Davis
Jan 16
prev sibling parent Jonathan M Davis via Digitalmars-d-learn writes:
On Friday, January 15, 2016 14:04:50 Nordlw via Digitalmars-d-learn wrote:
 I've made progress at the helper findingSplitter at

 https://github.com/nordlow/justd/blob/master/substitution.d#L122

 I need this for implementing a new Phobos lazy `substitute()` (or
 replace).

 I've done most logic (AFAICT in my head) but I can't make the
 call to Result() work as it fails as

 substitution.d(187,18): Error: struct
 substitution.findingSplitter!("a == b", string, string, string,
 string).findingSplitter.Result cannot deduce function from
 argument types !()(string, string, string, string), candidates
 are:
 substitution.d(126,12):        substitution.findingSplitter!("a
 == b", string, string, string, string).findingSplitter.Result()
 substitution.d(194,32): Error: template instance
 substitution.findingSplitter!("a == b", string, string, string,
 string) error instantiating
 substitution.d(196,12): Error: undefined identifier 'equal', did
 you mean alias 'Unqual'?
 /home/per/Work/justd/traits_ex.d(64,13): Warning: statement is
 not reachable

 What have I missed?
Well, the last error is caused by not import equal in that code (since the imports that would import it are local imports elsewhere in the module). As for the main error, you have parens on the declaration of Result. static struct Result() I don't know why you put them there, since Result is already effectively templated by being inside of a templated function, and having it requires that Result than have !() as a template argument when you're constructing it. So, I'd say that you should just remove the parens - or if you have a good reason that I can't think of which makes it make sense to put the parens on Result, then you'll need to use !() when constructing it. In any case, having the parens there but not using !() when constructing the Result is what gives you the error you're seeing. If you remove the parens, you get something more like substitution.d(159): Error: template instance hasSlicing!R template 'hasSlicing' is not defined substitution.d(160): Error: template instance hasLength!R template 'hasLength' is not defined substitution.d(176): Error: static assert "Handle R without slicing" substitution.d(195): instantiated from here: findingSplitter!("a == b", string, string, string, string) Adding the appropriate imports results in something along the lines of substitution.d(177): Error: static assert "Handle R without slicing" substitution.d(196): instantiated from here: findingSplitter!("a == b", string, string, string, string) Beyond that, I'd have to figure out exactly what you're up to, but it looks like that static assert is probably there to indicate that code needs to be added as opposed to there being another bug that needs fixing. In any case, that should at least help you make progress. - Jonathan M Davis
Jan 15