InstanceOf Template during runtime in a variant

Ali Çehreli acehreli at yahoo.com
Mon Feb 3 11:09:26 PST 2014


On 02/03/2014 10:15 AM, Andre wrote:
 >
 > I want to check whether the value stored in
 > variant v is a type of Decimal during runtime.
 > Is there a nice way?
 >
 > Kind regards
 > André
 >
 > import std.variant;
 >
 > struct Decimal(int scale, int precision){
 >      int _precision = precision;
 >      int _scale = scale;

This is unrelated to your question but you don't need those members as 
the two template parameters 'scale' and 'precision' are available.

If you needed 'precision' and 'scale' be variables, then you probably 
don't want to make Decimal a template but I can't be sure from here. :)

 >
 >      this(string value){/*...*/}
 > }
 >
 > void main(){
 >      Variant v = Decimal!(10,2)("123.00");
 > }

Ali



More information about the Digitalmars-d-learn mailing list