digitalmars.D.learn - Pass symbol to template?
- JS (13/13) Jul 19 2013 I have some templates to help initialize things, like a property
- John Colvin (4/17) Jul 19 2013 There isn't a way AFAIK
- JS (4/31) Jul 19 2013 I'm just passing short string literals to represent variable
I have some templates to help initialize things, like a property getter and setter. mixin(Property!("Name", int)); creates a property named Name with type int. I'd like to be able to call it like mixin(Property!(Name, int)); (Name is a symbol but undefined at the mixin site(since it will be defined once the mixin is done) I doubt this is possible in any way because it requires the compiler to allow such undefined symbols but would be nice... e.g., template Property(lazy alias name, type) { ... } but who knows, maybe I'm wrong and there is some way to do this?
Jul 19 2013
On Friday, 19 July 2013 at 08:08:25 UTC, JS wrote:I have some templates to help initialize things, like a property getter and setter. mixin(Property!("Name", int)); creates a property named Name with type int. I'd like to be able to call it like mixin(Property!(Name, int)); (Name is a symbol but undefined at the mixin site(since it will be defined once the mixin is done) I doubt this is possible in any way because it requires the compiler to allow such undefined symbols but would be nice... e.g., template Property(lazy alias name, type) { ... } but who knows, maybe I'm wrong and there is some way to do this?There isn't a way AFAIK You can use the q{...} syntax though, which is particularly nice for passing large code strings.
Jul 19 2013
On Friday, 19 July 2013 at 08:40:09 UTC, John Colvin wrote:On Friday, 19 July 2013 at 08:08:25 UTC, JS wrote:I'm just passing short string literals to represent variable names... It's not a huge deal but I wanted to avoid the quotes if I could(since they serve no real purpose).I have some templates to help initialize things, like a property getter and setter. mixin(Property!("Name", int)); creates a property named Name with type int. I'd like to be able to call it like mixin(Property!(Name, int)); (Name is a symbol but undefined at the mixin site(since it will be defined once the mixin is done) I doubt this is possible in any way because it requires the compiler to allow such undefined symbols but would be nice... e.g., template Property(lazy alias name, type) { ... } but who knows, maybe I'm wrong and there is some way to do this?There isn't a way AFAIK You can use the q{...} syntax though, which is particularly nice for passing large code strings.
Jul 19 2013