A simplification of the RvalueRef idiom
Satoshi via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Nov 22 13:55:57 PST 2016
On Tuesday, 22 November 2016 at 19:16:56 UTC, Ali Çehreli wrote:
> On 11/22/2016 08:05 AM, Satoshi wrote:
> I don't have extensive experience with other languages. In
> fact, the only other languages that I can claim proficiency are
> C and C++. (I also know Python just enough to find it
> incredible how it's used in the industry. Let's not get in to
> that discussion but I really tried and failed... in industry...
> :) ) Given that experience, I still find D a very useful tool.
>
D is one o the best languages what exists, it's reason why I'm
using it. But some issues are solved better in other languages
like rust, go or swift.
> Agreed but it opens the door for bugs. Assuming
>
> struct A { int a; }
> struct B { int b; int c; }
>
> void foo(int, int, int);
>
> If foo(1, 2, 3) meant foo(A(1), B(2, 3)) today, it could
> silently mean foo(A(1, 2), B(3)) if one moved one member from
> one struct to the other.
>
> Then there are other corner cases:
>
> writeln(1, 2, 3);
>
> Should that print the integers or A(1) and B(2, 3)? It's always
> better to be explicit.
>
argument expand should be applied only to the last argument and
cannot be used in variadic templates. Like in my simple example
where I exactly know what function will do, but I want to call it
by simplest way.
It actually works with classes, but no with structs.
> import std.stdio;
>
> struct Point {
> int x;
> int y;
> }
>
> struct GraphicsContext {
> static GraphicsContext current() {
> return GraphicsContext();
> }
>
> void moveTo(Point point) {
> writefln("Moving to %s", point);
> }
>
> void lineTo(Point point) {
> writefln("Drawing line to %s", point);
> }
> }
>
> void goTo(GraphicsContext gc, int x, int y) {
> gc.moveTo(Point(x, y));
> }
>
> void drawTo(GraphicsContext gc, int x, int y) {
> gc.lineTo(Point(x, y));
> }
>
> void main() {
> auto gc = GraphicsContext.current;
> gc.goTo(70, 70); // <-- Clean syntax
> gc.drawTo(70, 170);
> }
But I need to write overload function for every function taking
simple messengers like Point/Size/Rectangle
More information about the Digitalmars-d-learn
mailing list