digitalmars.D.learn - InstanceOf Template during runtime in a variant
- Andre (15/15) Feb 03 2014 Hi,
- Dicebot (4/4) Feb 03 2014 No. Variant only stores TypeInfo for its current data and
- Dicebot (2/2) Feb 03 2014 (you can check for specific type via `v.type() ==
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (6/20) Feb 03 2014 This is unrelated to your question but you don't need those members as
- Andre (5/31) Feb 03 2014 Thanks for the answers. Yes you are correct, the 2 members are superflou...
- Dicebot (4/7) Feb 03 2014 There is a proposal in Phobos review queue
- Gary Willoughby (4/12) Aug 06 2015 I notice he is active again and the repo has been currently
Hi, 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(string value){/*...*/} } void main(){ Variant v = Decimal!(10,2)("123.00"); }
Feb 03 2014
No. Variant only stores TypeInfo for its current data and templated struct will have a totally different type for each set of template arguments. Their similarity exists only during compile-time.
Feb 03 2014
(you can check for specific type via `v.type() == typeid(Decimal!(10,2))` though)
Feb 03 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
Feb 03 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"); > } AliThanks 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é
Feb 03 2014
On Monday, 3 February 2014 at 19:35:47 UTC, Andre wrote:Btw. having std.decimal in the library would be really nice;) Kind regards AndréThere is a proposal in Phobos review queue (http://wiki.dlang.org/Review_Queue) but its author does not seem to be active anymore so it moves nowhere.
Feb 03 2014
On Monday, 3 February 2014 at 19:47:56 UTC, Dicebot wrote:On Monday, 3 February 2014 at 19:35:47 UTC, Andre wrote:I notice he is active again and the repo has been currently worked on. Can someone give him a nudge and get this process moving?Btw. having std.decimal in the library would be really nice;) Kind regards AndréThere is a proposal in Phobos review queue (http://wiki.dlang.org/Review_Queue) but its author does not seem to be active anymore so it moves nowhere.
Aug 06 2015