to!() conversion between objects

kenji hara k.hara.pg at gmail.com
Thu Oct 20 04:53:04 PDT 2011


2011/10/20 Piotr Szturmaj <bncrbme at jadamspam.pl>:
> Robert Jacques wrote:
>>
>> On Wed, 19 Oct 2011 14:16:31 -0400, Piotr Szturmaj
>> <bncrbme at jadamspam.pl> wrote:
>>>
>>> bearophile wrote:
>>>>
>>>> Piotr Szturmaj:
>>>>
>>>>> I have written a simple conversion template for tuples, structs and
>>>>> classes:
>>>>
>>>> Do you have some use case to show me?
>>>
>>> class C
>>> {
>>> int i;
>>> string s;
>>> }
>>>
>>> struct S
>>> {
>>> string s;
>>> float f;
>>> }
>>>
>>> auto c = to!C(S("5", 2.5f));
>>> assert(c.i == 5 && c.s == "2.5");
>>>
>>
>> So C's s field maps to S's f field, not it's s field? That seems
>> unintuitive and bug prone.

I'm agree with bearophile.

> This isn't name to name mapping but field to field mapping.

I think std.conv.to should provide the *safe natural conversion*.
Field-to-field conversion seems not natural, and it is called
'Structural conversion'.

Kenji Hara


More information about the Digitalmars-d mailing list