digitalmars.D.learn - Templated static opCall in non-templated struct
- Matthew Dudley (18/18) Feb 10 2014 Here's the gist of what I'm trying to do:
- Namespace (4/22) Feb 10 2014 Welcome to my world ;)
- Matthew Dudley (5/32) Feb 11 2014 I'm not sure that the same ambiguity is here in this case. Since
- Philippe Sigaud (2/9) Feb 11 2014 Did you try using a templated constructor?
- Matthew Dudley (9/19) Feb 11 2014 Like this?
- Frustrated (8/26) Feb 11 2014 You can't do this! you are calling Foo as if it is a template...
- Matthew Dudley (3/34) Feb 11 2014 Well since Foo isn't templated, shouldn't the compiler know to
Here's the gist of what I'm trying to do: struct Foo { public: int i; int j; static opCall(int i)(int j, int k) { return Foo(i+j,i+k); } } void main() { auto bob = Foo!(1)(2,3); //Error: template instance Foo!1 Foo is not a template declaration, it is a struct } I'm trying to template the static opCall function, not the struct. Is there a way to do disambiguate between the two?
Feb 10 2014
On Tuesday, 11 February 2014 at 00:00:06 UTC, Matthew Dudley wrote:Here's the gist of what I'm trying to do: struct Foo { public: int i; int j; static opCall(int i)(int j, int k) { return Foo(i+j,i+k); } } void main() { auto bob = Foo!(1)(2,3); //Error: template instance Foo!1 Foo is not a template declaration, it is a struct } I'm trying to template the static opCall function, not the struct. Is there a way to do disambiguate between the two?Welcome to my world ;) http://forum.dlang.org/thread/hdocnxglxmfpacnpmouh forum.dlang.org
Feb 10 2014
I'm not sure that the same ambiguity is here in this case. Since the opCall is static, the only other thing that the template could apply to is the struct, which you can check that it doesn't from the struct definition. On Tuesday, 11 February 2014 at 00:05:08 UTC, Namespace wrote:On Tuesday, 11 February 2014 at 00:00:06 UTC, Matthew Dudley wrote:Here's the gist of what I'm trying to do: struct Foo { public: int i; int j; static opCall(int i)(int j, int k) { return Foo(i+j,i+k); } } void main() { auto bob = Foo!(1)(2,3); //Error: template instance Foo!1 Foo is not a template declaration, it is a struct } I'm trying to template the static opCall function, not the struct. Is there a way to do disambiguate between the two?Welcome to my world ;) http://forum.dlang.org/thread/hdocnxglxmfpacnpmouh forum.dlang.org
Feb 11 2014
On Tue, Feb 11, 2014 at 1:05 AM, Namespace <rswhite4 googlemail.com> wrote:static opCall(int i)(int j, int k) { return Foo(i+j,i+k); }auto bob = Foo!(1)(2,3); //Error:Welcome to my world ;) http://forum.dlang.org/thread/hdocnxglxmfpacnpmouh forum.dlang.orgDid you try using a templated constructor?
Feb 11 2014
On Tuesday, 11 February 2014 at 19:15:25 UTC, Philippe Sigaud wrote:On Tue, Feb 11, 2014 at 1:05 AM, Namespace <rswhite4 googlemail.com> wrote:Like this? this(int i)(int j, int k) { this.i = i + j; this.j = i + k; } Same error.static opCall(int i)(int j, int k) { return Foo(i+j,i+k); }auto bob = Foo!(1)(2,3); //Error:Welcome to my world ;) http://forum.dlang.org/thread/hdocnxglxmfpacnpmouh forum.dlang.orgDid you try using a templated constructor?
Feb 11 2014
On Tuesday, 11 February 2014 at 00:00:06 UTC, Matthew Dudley wrote:Here's the gist of what I'm trying to do: struct Foo { public: int i; int j; static opCall(int i)(int j, int k) { return Foo(i+j,i+k); } } void main() { auto bob = Foo!(1)(2,3); //Error: template instance Foo!1 Foo is not a template declaration, it is a struct } I'm trying to template the static opCall function, not the struct. Is there a way to do disambiguate between the two?You can't do this! you are calling Foo as if it is a template... hence the error! Maybe the only solution is a new symbol such as Foo!!(1)(2,3) where !! tells the compiler that you are referencing an implicit function call and not a template. Would be an easy solution.
Feb 11 2014
On Wednesday, 12 February 2014 at 01:59:54 UTC, Frustrated wrote:On Tuesday, 11 February 2014 at 00:00:06 UTC, Matthew Dudley wrote:Well since Foo isn't templated, shouldn't the compiler know to apply the template to the function?Here's the gist of what I'm trying to do: struct Foo { public: int i; int j; static opCall(int i)(int j, int k) { return Foo(i+j,i+k); } } void main() { auto bob = Foo!(1)(2,3); //Error: template instance Foo!1 Foo is not a template declaration, it is a struct } I'm trying to template the static opCall function, not the struct. Is there a way to do disambiguate between the two?You can't do this! you are calling Foo as if it is a template... hence the error! Maybe the only solution is a new symbol such as Foo!!(1)(2,3) where !! tells the compiler that you are referencing an implicit function call and not a template. Would be an easy solution.
Feb 11 2014