digitalmars.D.learn - how can I ensure that a template instantiation is unique?
- Vlad Levenfeld (11/11) Jun 18 2014 I'm instantiating a couple of template structs that conflict with
- Andrew Edwards (11/19) Jun 18 2014 I don't think you want to set a default value. If you pass
- Andrea Fontana (3/14) Jun 19 2014 Maybe something like this:
- Andrea Fontana (2/19) Jun 19 2014 Of course Foo2 could be an enum :)
- Vlad Levenfeld (1/1) Jun 19 2014 Thanks! Mixin strings can punch through anything.
I'm instantiating a couple of template structs that conflict with each other. I'd like them to be unique types, automatically. So I tried this: template Foo (string unique_id = __FILE__~__LINE__.to!string) {...} but it didn't work. When I use this for templated functions, I get the file and line number where the function is instantiated. But in this case, I got the file and line number where the template was defined. Is there anything I can do to make sure each instantiated type is unique?
Jun 18 2014
On 6/19/14, 1:48 AM, Vlad Levenfeld wrote:I'm instantiating a couple of template structs that conflict with each other. I'd like them to be unique types, automatically. So I tried this: template Foo (string unique_id = __FILE__~__LINE__.to!string) {...} but it didn't work. When I use this for templated functions, I get the file and line number where the function is instantiated. But in this case, I got the file and line number where the template was defined. Is there anything I can do to make sure each instantiated type is unique?I don't think you want to set a default value. If you pass "__FILE__~__LINE__.to!string" during instantiation, it works every time: template Foo(string uniqueId) { alias Foo = uniqueId; } void main() { Foo!(__FILE__~__LINE__.to!string).writeln; }
Jun 18 2014
On Thursday, 19 June 2014 at 05:48:24 UTC, Vlad Levenfeld wrote:I'm instantiating a couple of template structs that conflict with each other. I'd like them to be unique types, automatically. So I tried this: template Foo (string unique_id = __FILE__~__LINE__.to!string) {...} but it didn't work. When I use this for templated functions, I get the file and line number where the function is instantiated. But in this case, I got the file and line number where the template was defined. Is there anything I can do to make sure each instantiated type is unique?Maybe something like this: http://dpaste.dzfl.pl/ce479a2f87f4
Jun 19 2014
On Thursday, 19 June 2014 at 07:26:12 UTC, Andrea Fontana wrote:On Thursday, 19 June 2014 at 05:48:24 UTC, Vlad Levenfeld wrote:Of course Foo2 could be an enum :)I'm instantiating a couple of template structs that conflict with each other. I'd like them to be unique types, automatically. So I tried this: template Foo (string unique_id = __FILE__~__LINE__.to!string) {...} but it didn't work. When I use this for templated functions, I get the file and line number where the function is instantiated. But in this case, I got the file and line number where the template was defined. Is there anything I can do to make sure each instantiated type is unique?Maybe something like this: http://dpaste.dzfl.pl/ce479a2f87f4
Jun 19 2014
Thanks! Mixin strings can punch through anything.
Jun 19 2014