About variant

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jan 27 14:47:05 PST 2015


On Tue, 27 Jan 2015 21:55:37 +0000, bioinfornatics wrote:

> On Tuesday, 27 January 2015 at 21:00:16 UTC, Justin Whear wrote:
>> On Tue, 27 Jan 2015 20:46:59 +0000, bioinfornatics wrote:
>>
>>> void main(){
>>> 	auto a = Alpha!(int)( 6);
>>> 	auto b = Alpha!(string)( "hello");
>>
>> The Alpha struct is not a template, only the constructor is.
>> Remove the explicit instantiations and IFTI does the work:
>>> void main(){
>>> 	auto a = Alpha( 6);
>>> 	auto b = Alpha( "hello");
> 
> Oh really cool

or this:

  import std.variant;

  struct Alpha {
    Variant something;

    this(T) (T v) {
      something = cast(Variant)v;
    }
  }

  void main () {
    Alpha a = 6;
    Alpha b = "hello";
  }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150127/1deb7746/attachment.sig>


More information about the Digitalmars-d-learn mailing list