Re: Multiple implicit type converters

2015-09-11 Thread Adam D. Ruppe via Digitalmars-d-learn
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

Re: Multiple implicit type converters

2015-09-11 Thread Meta via Digitalmars-d-learn
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

Multiple implicit type converters

2015-09-11 Thread Bahman Movaqar via Digitalmars-d-learn
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

Re: Multiple implicit type converters

2015-09-11 Thread Adam D. Ruppe via Digitalmars-d-learn
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

Re: Multiple implicit type converters

2015-09-11 Thread Dave Akers via Digitalmars-d-learn
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.

Re: Multiple implicit type converters

2015-09-11 Thread Bahman Movaqar via Digitalmars-d-learn
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

Re: Multiple implicit type converters

2015-09-11 Thread Bahman Movaqar via Digitalmars-d-learn
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

Re: Multiple implicit type converters

2015-09-11 Thread Bahman Movaqar via Digitalmars-d-learn
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