Le 2010-07-08 à 8:13, Andrei Alexandrescu a écrit :

> This is solid work! There's an opportunity here - it overlaps a LOT with 
> std.variant.Algebraic.


Indeed. It's great. But why is the protection level set to 'package'? Isn't it 
meant to be used outside of Phobos?


> Essentially it would be best if you integrated opDispatch, _onActiveDuck, and 
> friends inside Algebraic. Then Algebraic would become meta-duck - it still 
> supports any combination of types, but you can call any method they share 
> against the Algebraic.

One thing I've missed about Algebraic is the ability to switch on the type, 
somewhat like this:

        Algebraic!(A, B, C) x;
        switch (x.type) {
                case x.typecode!A:
                case x.typecode!B:
                case x.typecode!C:
                        ...
        }

Seems like this would be easy by switching on Any's _duckID, but this facility 
isn't exposed (it's all private).

Also, this approach using _duckID is a big difference from VariantN (and its 
derivative Algebraic), which stores a pointer to the typeid to identify the 
type instead of using a compile-time constant. I think the compile time 
constant is better since beside being switch-friendly it makes optimizations 
easier for the compiler.

So I think it'd be better to simply replace Algebraic's implementation with the 
one from Any. Or perhaps Algebraic and VariantN could be retrofitted so it can 
use a constant instead of a typeid pointer, but I'm not sure how it'd work.


> P.S. I *love* the trick with the homonym inner namespace! It solves the 
> naming problem so elegantly. I'll use it in RefCounted too.

It's a nice trick and a good application of it.

In fact, I remember myself proposing something similar to allow properties with 
overloaded operators a few months ago when the property debate was raging. :-)

-- 
Michel Fortin
[email protected]
http://michelf.com/



_______________________________________________
phobos mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/phobos

Reply via email to