Disappointing inflexibility of argument passing with "alias this"

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Mon Feb 22 17:02:21 PST 2016


On Monday, 22 February 2016 at 18:28:04 UTC, Dicebot wrote:
> On 02/22/2016 08:20 PM, rsw0x wrote:
>> On Monday, 22 February 2016 at 18:11:58 UTC, H. S. Teoh wrote:
>>> On Mon, Feb 22, 2016 at 06:07:26PM +0000, rsw0x via 
>>> Digitalmars-d wrote:
>>>> On Monday, 22 February 2016 at 17:29:40 UTC, Adam D. Ruppe 
>>>> wrote:
>>>> >[...]
>>>>
>>>> explicitly-implicit constructors are badly needed, I could 
>>>> write an essay on this
>>>
>>> AFAICT, implicit ctors are not supported by design.
>>>
>>>
>>> T
>> 
>> It is a bad design.
>
> It is arguable opinion.

Yeah. Sometimes having implicit conversions is great. Other 
times, it creates tons of problems. C++ allows a lot of implicit 
stuff, and it becomes really easy to have unexpected conversions 
going on, and it can be difficult to figure out exactly what code 
is being called. For the most part, D doesn't have any of those 
problems, but it arguably loses some usability as a result. So, 
it's highly debatable.

Personally, I think that the big place that implicit conversions 
are a disaster is generic code. It makes it really easy to have 
stuff pass template constraints due to implicit conversions and 
then have the wrong behavior inside the templated code, because 
the conversion is never forced, and it doesn't act the same way 
as it would if the conversion had been forced and possibly even 
ends up being converted for some of expressions in the function 
and not converted in others. For non-templated code, it's a lot 
more debatable, but when it comes to templated code, I really 
wish that alias this didn't exist.

- Jonathan M Davis


More information about the Digitalmars-d mailing list