Is it possible to handle 'magic' property assignments a'la PHP?
H. S. Teoh
hsteoh at quickfur.ath.cx
Sat Jan 4 13:08:05 PST 2014
On Sat, Jan 04, 2014 at 07:52:11PM +0000, Adam D. Ruppe wrote:
> On Saturday, 4 January 2014 at 19:26:50 UTC, Gary Willoughby wrote:
> >Got it!
>
> opDispatch rox, and there's all kinds of crazy stuff you can do with
> it. In my dom.d, I used it for three things:
[...]
Somebody has also used opDispatch to do vector swizzling, such that:
auto v = vec.wxzy;
is equivalent to:
auto v = [vec[0], vec[1], vec[2], vec[1]];
It's also possible to implement Roman numerals with opDispatch that
doesn't require a string literal:
Roman.II == 2
Roman.VII == 7
... etc.
by parsing the identifier passed to opDispatch at compile-time.
Of course, these are arguably clever hacks than true, properly-motivated
examples, but still, they exemplify what Andrei meant when he said that
the power of opDispatch is largely still unexplored territory.
T
--
It's amazing how careful choice of punctuation can leave you hanging:
More information about the Digitalmars-d-learn
mailing list