std.conv - custom string to struct conversion ?

Douglas Petterson someone at somewhere.nz
Fri Aug 2 00:14:24 PDT 2013


On Friday, 2 August 2013 at 05:09:14 UTC, Jonathan M Davis wrote:
> On Friday, August 02, 2013 06:50:01 Douglas Petterson wrote:
>> Is there a way to convert a string to a struct, similarly to 
>> the
>> conversion of a struct to a custom string representation ?
>> 
>> The following code works fine when using format("%s",C) or
>> to!string(C):
>> 
>>      struct sCustomConv
>>      {
>>          string toString()
>>          {
>>              return "My custom representation";
>>          }
>>      }
>> 
>>      sCustomConv C;
>>      string MyBackup = to!string(C);
>> 
>> But I can't find which class operator must be overloaded (or 
>> more
>> simply how-to) to make this possible:
>> 
>>      C = to!sCustomConv(MyBackup);
>
> http://stackoverflow.com/questions/8351245/override-tot-for-used-defined-t-in-d
>
> - Jonathan M Davis

That perfectly fits to my need, thx.



More information about the Digitalmars-d-learn mailing list