digitalmars.D.learn - Voldemort Type Construction Error
- =?UTF-8?B?Tm9yZGzDtnc=?= (21/21) Jan 15 2016 I've made progress at the helper findingSplitter at
- Anon (4/5) Jan 15 2016 In line 126, `static struct Result()` is a template. Either drop
- =?UTF-8?B?Tm9yZGzDtnc=?= (4/9) Jan 15 2016 Ahh, annoying mistake.
- Kapps (4/14) Jan 15 2016 At least for functions, making them templates provides some
- Jonathan M Davis via Digitalmars-d-learn (21/38) Jan 16 2016 It does
- Jonathan M Davis via Digitalmars-d-learn (26/47) Jan 15 2016 Well, the last error is caused by not import equal in that code (since t...
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 2016
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 2016
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:Ahh, annoying mistake. Why is this allowed? /PerWhat 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 2016
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: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.On Friday, 15 January 2016 at 14:04:50 UTC, Nordlöw wrote:Ahh, annoying mistake. Why is this allowed? /PerWhat 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 2016
On Saturday, January 16, 2016 06:06:03 Kapps via Digitalmars-d-learn wrote:On Friday, 15 January 2016 at 20:04:47 UTC, Nordlöw wrote: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 DavisOn Friday, 15 January 2016 at 16:51:24 UTC, Anon wrote: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.On Friday, 15 January 2016 at 14:04:50 UTC, Nordlöw wrote:Ahh, annoying mistake. Why is this allowed? /PerWhat 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 16 2016
On Friday, January 15, 2016 14:04:50 Nordlöw 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 2016