digitalmars.D.learn - How to retrieve template parameters
- BCS (19/19) Nov 21 2005 How can you get the specialization parameters for a template from outsid...
- Sean Kelly (4/6) Nov 21 2005 You can't. This is why C++ defines a set of standard typedefs that must...
- BCS (10/16) Nov 21 2005 What, if any, problem arise with a syntax allowing that. Just as a start...
- Sean Kelly (8/24) Nov 21 2005 I'm not sure I like it, as it introduces symbols into the interface that...
- BCS (10/34) Nov 21 2005 ok, then how about public/package/private or somthing like that.
- Thomas Kuehne (23/64) Nov 25 2005 -----BEGIN PGP SIGNED MESSAGE-----
- BCS (21/52) Nov 26 2005 No good. What I'm looking for must work on an alias for a template membe...
How can you get the specialization parameters for a template from outside the template? This is what I have tried. template test(int i) { struct j {int k;}; } int main() { alias test!(1).j t; alias test!(2).j u; printf("%d\n", t.i); printf("%d\n", u.i); return 0; } The point of what I am trying is to do things like this: alias test!(t.i + u.i) v; If what I am trying to do is not possible or is rather convoluted, I would like to propose that a simple way be provided to do this. Such as allow access to them as properties.
Nov 21 2005
BCS wrote:How can you get the specialization parameters for a template from outside the template? This is what I have tried.You can't. This is why C++ defines a set of standard typedefs that must be implemented by containers and such. Sean
Nov 21 2005
In article <dltjb9$l0q$1 digitaldaemon.com>, Sean Kelly says...BCS wrote:What, if any, problem arise with a syntax allowing that. Just as a starting point, how about this: template t(int i, T) { T fn(){...} } int t_i = t!(0,int).i; // sets t_i to 0; t!(0,int).T t_T; // t_T is of type int t!(1,real).fn.T t_fn_T; // t_fn_T is of type realHow can you get the specialization parameters for a template from outside the template? This is what I have tried.You can't. This is why C++ defines a set of standard typedefs that must be implemented by containers and such. Sean
Nov 21 2005
BCS wrote:In article <dltjb9$l0q$1 digitaldaemon.com>, Sean Kelly says...I'm not sure I like it, as it introduces symbols into the interface that might be implementation details. I'd rather stick to the manual method: class C(int i) { const int count = i; } const int c = C!(1).count; SeanBCS wrote:What, if any, problem arise with a syntax allowing that. Just as a starting point, how about this: template t(int i, T) { T fn(){...} } int t_i = t!(0,int).i; // sets t_i to 0;How can you get the specialization parameters for a template from outside the template? This is what I have tried.You can't. This is why C++ defines a set of standard typedefs that must be implemented by containers and such.
Nov 21 2005
In article <dltlpm$n12$1 digitaldaemon.com>, Sean Kelly says...BCS wrote:ok, then how about public/package/private or somthing like that. Further more how can the above be extended to somthing like: template fn(int I) { void fn(){...} const int count = I } alias fn!(1).fn() hidden; hidden.count // error: can't get that from thisIn article <dltjb9$l0q$1 digitaldaemon.com>, Sean Kelly says...I'm not sure I like it, as it introduces symbols into the interface that might be implementation details. I'd rather stick to the manual method: class C(int i) { const int count = i; } const int c = C!(1).count; SeanBCS wrote:What, if any, problem arise with a syntax allowing that. Just as a starting point, how about this: template t(int i, T) { T fn(){...} } int t_i = t!(0,int).i; // sets t_i to 0;How can you get the specialization parameters for a template from outside the template? This is what I have tried.You can't. This is why C++ defines a set of standard typedefs that must be implemented by containers and such.
Nov 21 2005
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 BCS schrieb am 2005-11-22:In article <dltlpm$n12$1 digitaldaemon.com>, Sean Kelly says...| import std.stdio; | | template fn(int I) | { | void fn(){...} | const int count = I | } | alias fn!(1) hidden; | | int main() | { | writefln("%s", hidden.count); | return 0; | } Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFDh8W+3w+/yD4P9tIRAixpAKC2SxssMjy2BuwShZ+fJtVApr98cgCfQ+C+ TM7c2K2EAzE/usuqq/zOzJc= =NjvR -----END PGP SIGNATURE-----BCS wrote:ok, then how about public/package/private or somthing like that. Further more how can the above be extended to somthing like: template fn(int I) { void fn(){...} const int count = I } alias fn!(1).fn() hidden; hidden.count // error: can't get that from thisIn article <dltjb9$l0q$1 digitaldaemon.com>, Sean Kelly says...I'm not sure I like it, as it introduces symbols into the interface that might be implementation details. I'd rather stick to the manual method: class C(int i) { const int count = i; } const int c = C!(1).count; SeanBCS wrote:What, if any, problem arise with a syntax allowing that. Just as a starting point, how about this: template t(int i, T) { T fn(){...} } int t_i = t!(0,int).i; // sets t_i to 0;How can you get the specialization parameters for a template from outside the template? This is what I have tried.You can't. This is why C++ defines a set of standard typedefs that must be implemented by containers and such.
Nov 25 2005
No good. What I'm looking for must work on an alias for a template member. e.g. alias fn!(1).fn() hidden; hidden() // this must be a function hidden.count // this must be a const int The real purpose of this would be something like this template t(int i) { typedef real t; } template math(T, U) { // abusing the syntax to say: // T & U must be from template t but I don't care what i is. static assert(is(T == t!(*).t) && is(U == t!(*).t); t!(T.i + U.i).t opMul(T a, U b) { return a*b; } t!(T.i - U.i).t opDiv(T a, U b) { return a/b; } t!(T.i).t opAdd(T a, T b) { return a+b; } t!(T.i).t opSub(T a, T b) { return a-b; } } In article <u6tk53-rdd.ln1 birke.kuehne.cn>, Thomas Kuehne says...BCS schrieb am 2005-11-22:.....In article <dltlpm$n12$1 digitaldaemon.com>, Sean Kelly says...ok, then how about public/package/private or somthing like that. Further more how can the above be extended to somthing like: template fn(int I) { void fn(){...} const int count = I } alias fn!(1).fn() hidden; hidden.count // error: can't get that from this| import std.stdio; | | template fn(int I) | { | void fn(){...} | const int count = I | } | alias fn!(1) hidden; | | int main() | { | writefln("%s", hidden.count); | return 0; | } Thomas
Nov 26 2005