InstanceOf Template during runtime in a variant

Andre andre at s-e-a-p.de
Mon Feb 3 11:35:59 PST 2014


Am 03.02.2014 20:09, schrieb Ali Çehreli:
> 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
>

Thanks for the answers. Yes you are correct, the 2 members are superflous.
Btw. having std.decimal in the library would be really nice;)

Kind regards
André



More information about the Digitalmars-d-learn mailing list