Calypso/LanguageAdditions

From D Wiki
Revision as of 16:48, 29 June 2016 by Syniurge (talk | contribs) (WIP draft)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

In order.

scope ref

A feature recurringly requested, its absence considered by many as producing terrible looking code, yet despite pull requests never made it:

http://forum.dlang.org/post/mailman.3720.1453131378.22025.digitalmars-d@puremagic.com

(WIP) Not being able to pass rvalue to

Whether the reference escapes or not isn't checked, so the current implementation is a hack reaping the code beautification benefits while disregarding all safety:

https://github.com/Syniurge/Calypso/commit/652780400cac85aa75670eba263c93e48bf2432f https://github.com/Syniurge/Calypso/commit/af60ca29add17df0f45cd722c39d756668d453cf

Regarding the recurring

Explicitly implicit constructor calls for functions arguments

In C++ constructors may be implicitly called by default unless marked explicit. This means that if a passed argument ArgTy doesn't match any of the function overloads' parameter type ParamTy and if ParamTy is a class or struct, the C++ compiler look for a constructor from ParamTy that takes an ArgTy argument and implicitly replace f(original_arg) by f(ParamTy(original_arg)).

D doesn't have implicit constructor calls. It may avoid some surprises, but a drawback is a lot more verbose code for instance whenever a custom string or reference class is needed:

class CustomStrClass
{
  (...)
  CustomStrClass(string s) {...}
}

void Foo(CustomStrClass arg1, CustomStrClass arg2);

void Bar() {
  Foo(CustomStrClass("some string"), CustomStrClass("another string"));
}

This is a very common occurrence for C++ libraries. Using Qt means plastering the code with QSomeFunc(QString("lorem ipsum")), using OpenCV means InputArray or OutputArray everywhere, etc.

Implicit constructor calls have been little discussed as far as I know, but desired from times to times:

 http://forum.dlang.org/post/ltdchmnokbgyjctiqxru@forum.dlang.org

The @implicit attribute was added to DMD in order to enable implicit constructor calls, and in Calypso is applied to all C++ non-explicit constructors:

https://github.com/Syniurge/Calypso/commit/999bd81cd094584a1db2357230888bf7d96e7d09 https://github.com/Syniurge/Calypso/commit/66df399a0d0bf5f3ccd8c96db354635eef86480b https://github.com/Syniurge/Calypso/commit/4e080f5cd1fa636a98d50d35a2632abcdcbe75cc https://github.com/Syniurge/Calypso/commit/471fad6a1dba98c752d1dee1f81e836d16a89320

Considered: enabling UFCS for overloaded operators