half datatype?
Manu
turkeyman at gmail.com
Sun Nov 18 16:32:18 PST 2012
On 19 November 2012 01:58, Manu <turkeyman at gmail.com> wrote:
> I'm sure that's true, I've just always used it to gain access to members
> of embedded types, kinda of like abstraction for 'struct's. It hadn't
> occurred to me to support explicit casting in that way.
**cough** IMPLICIT casting.
On 18 November 2012 18:31, Andrei Alexandrescu <
> SeeWebsiteForEmail at erdani.org> wrote:
>
>> On 11/18/12 7:30 AM, Manu wrote:
>>
>>> On 18 November 2012 14:01, David Nadlinger <see at klickverbot.at
>>>
>>> <mailto:see at klickverbot.at>> wrote:
>>>
>>> On Sunday, 18 November 2012 at 11:21:37 UTC, Manu wrote:
>>>
>>> someFloat = someHalf <- doesn't work, because a cast operator
>>> expects an
>>> explicit cast, even though this is a lossless conversion and
>>> should be
>>> exactly the same as someDouble = someFloat.
>>>
>>> Thoughts?
>>>
>>>
>>> ---
>>> struct Half {
>>> float toFloat() { return 3.14f; }
>>> alias toFloat this;
>>> }
>>>
>>> void test() {
>>> Half h;
>>> float f = h;
>>> double d = h;
>>> }
>>> ---
>>>
>>> Works for you?
>>>
>>>
>>> Interesting approach to the implicit cast problem. Very handy trick.
>>>
>>
>> Well that was quite explicitly part of the purpose of alias this.
>>
>> Andrei
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20121119/ca663435/attachment.html>
More information about the Digitalmars-d
mailing list