On Friday, 11 September 2015 at 16:25:53 UTC, Bahman Movaqar
wrote:
As only one `alias this` is possible for any type, how should
one implement multiple implicit type converters?
multiple alias this is supposed to work and might some day fyi
But for today, the explicit is the only way to go
On Friday, 11 September 2015 at 16:25:53 UTC, Bahman Movaqar
wrote:
As only one `alias this` is possible for any type, how should
one implement multiple implicit type converters?
Actually I'm looking for something similar to Groovy's `asType`
method[1]. An example in Groovy:
Point p
As only one `alias this` is possible for any type, how should one
implement multiple implicit type converters?
Actually I'm looking for something similar to Groovy's `asType`
method[1]. An example in Groovy:
Point p = new Point(1, 1)
assert (p as BigDecimal[]) == [1, 1]
assert
On Friday, 11 September 2015 at 19:51:09 UTC, Dave Akers wrote:
Would it be possible to create it as an 'as' template?
Yeah, the way I'd do it is something like:
T as(T)() {
import std.traits;
static if(isIntegral!T)
return to!T(convert_to_some_int);
else static
On Friday, 11 September 2015 at 19:34:46 UTC, Bahman Movaqar
wrote:
On Friday, 11 September 2015 at 16:33:52 UTC, Meta wrote:
The only ways to get implicit conversion between two types in
D are through `alias this`, inheritance, or implementing an
interface.
That's enough for me, I suppose.
On Friday, 11 September 2015 at 19:51:09 UTC, Dave Akers wrote:
That's enough for me, I suppose.
I am thinking of having a family of functions in my
structs/classes as `as` family, such as `asDouble`, `asFooBar`.
Would it be possible to create it as an 'as' template?
Hmm...there's already
On Friday, 11 September 2015 at 16:33:52 UTC, Meta wrote:
The only ways to get implicit conversion between two types in D
are through `alias this`, inheritance, or implementing an
interface.
That's enough for me, I suppose.
I am thinking of having a family of functions in my
structs/classes
On Friday, 11 September 2015 at 16:31:46 UTC, Adam D. Ruppe wrote:
explicit is the only way to go. That's easy to do, just write
like a .get method or something that does the conversion and
returns it.
Fair enough. Type conversion is one of those spots that I'd like
it to as explicit as