opCast cannot implicitly convert a.opCast of type X to Y
aliak
something at something.com
Thu Feb 15 01:12:32 UTC 2018
On Thursday, 15 February 2018 at 00:34:33 UTC, Meta wrote:
> On Thursday, 15 February 2018 at 00:27:40 UTC, Meta wrote:
>> On Wednesday, 14 February 2018 at 23:46:30 UTC, aliak wrote:
>>> On Wednesday, 14 February 2018 at 15:14:24 UTC, Meta wrote:
>>>
>>> Ooh yes, of course! Thank you :)
>>
>> Even better:
>>
>> import std.conv;
>>
>> auto b = a.map!(to!float);
>
> Actually, that won't quite work without redefining map a little:
>
> Optional!U map(alias f, U = typeof(f(t.init)))()
> {
> etc...
> }
Ah yes, true, also auto return would work. But then you'd still
need to do the typeof(f(T.init)) evaluation in the body... plus
you lose being able to see an explicit return type i guess...
hmm. So nevermind :)
Though a free function would be good me thinks. Then you could
use it seamlessly with std.algorithm.map.
Optional!U map(alias f, T, U = typeof(f(T.init)))(Optional!T opt)
{
return Optional!U(f(opt.t));
}
Cheers,
- Ali
More information about the Digitalmars-d-learn
mailing list