www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Is it a Variant?

reply Steve Teale <steve.teale britseyeview.com> writes:
I think I remember seeing that std.variant is being updated.

Is there some way that an efficient test could be slipped in there that
would work in templates. The best my fuzzy brain can come up with this
morning is not wonderful:

(typeof(target).stringof.indexOf("VariantN!(maxSize)") == 0)

Steve
Oct 08 2011
next sibling parent "Nick Sabalausky" <a a.a> writes:
"Steve Teale" <steve.teale britseyeview.com> wrote in message 
news:j6r6tc$2kh7$1 digitalmars.com...
I think I remember seeing that std.variant is being updated.

 Is there some way that an efficient test could be slipped in there that
 would work in templates. The best my fuzzy brain can come up with this
 morning is not wonderful:

 (typeof(target).stringof.indexOf("VariantN!(maxSize)") == 0)
If there isn't already one, it would be easy to add: enum is_std_variant_Variant = true; static if(traits(_compiles, target.is_std_variant_Variant)) {} Although I would think the language itself would have some way to check if a type is an instantiation of a particular templated type...
Oct 08 2011
prev sibling parent reply "Robert Jacques" <sandford jhu.edu> writes:
On Sun, 09 Oct 2011 00:11:24 -0400, Steve Teale <steve.teale britseyeview.com>
wrote:
 I think I remember seeing that std.variant is being updated.

 Is there some way that an efficient test could be slipped in there that
 would work in templates. The best my fuzzy brain can come up with this
 morning is not wonderful:

 (typeof(target).stringof.indexOf("VariantN!(maxSize)") == 0)

 Steve
Yes, there is. Variant is now a struct so: is(typeof(target)==Variant) works just like you'd expect.
Oct 08 2011
parent Steve Teale <steve.teale britseyeview.com> writes:
On Sun, 09 Oct 2011 01:39:10 -0400, Robert Jacques wrote:

 Yes, there is. Variant is now a struct so:
 
 is(typeof(target)==Variant)
 
 works just like you'd expect.
So it does. Thanks.
Oct 09 2011