UFCS for classes with opCall( ... )

ParticlePeter ParticlePeter at gmx.de
Sat Jun 1 05:22:14 PDT 2013


Hello,

after watching Walters Talk about Component Programming ( link 
Bellow ) I was quite fond of his pipelining approach.
I tried the following and had to realize that this way using UFCS 
isn't working ( or I do something wrong ).

// I want to write On Canvas1 | draw Shape1 | draw Shape2 | ... 
in code ( not working ):
canvas1.shape1.shape2.draw()

// Which in essence would be ( working ):
shape2( shape1( canvas1 ) ).draw()

// With these Classes

class Canvas  {
public:
	drawTarget()  {
		// activate as Draw Target
	}
}

class Shape  {
public:
	Shape opCall( Canvas canvas ) {
		canvas.drawTarget() ;
		return this ;
	}

	Shape opCall( Shape otherShape ) {
		otherShape.draw()
		return this ;
	}

	void draw() {
		// Draw yourself Draw calls
	}
}

FYI: Its OpenGL stuff, Canvas would be the Frambuffer or FBOs, 
and Shape abstrcted draw calls. I have some more building blocks 
which would nicely fit into this pipelining.

1. Is there any way that I could make my wish syntax work with 
D's current features ?
2. Is there a reason that this does not work with UFCS, besides 
"not implemented yet" ?
3. If not 1. Would this be a valid feature requst ?

Thanks for any insights,

Cheers, ParticlePeter !


Walters Talk:
https://www.youtube.com/watch?v=cQkBOCo8UrE


More information about the Digitalmars-d-learn mailing list