On 03/05/2012 07:05 AM, Andrei Alexandrescu wrote:

Great! I meant for a long time to suggest Steve Schveighoffer to accept
a variadic number of predicates for the red-black tree. This is even
more general (nevertheless I still think it would be great if
RedBlackTree accepted multiple predicates).

Andrei



The point of that would just be to have your collection sorted multiple ways, right? It kinda seems like multi_index is most useful in that case, but then I don't use multi_index that often, so I don't know.

It would be a nice addition for RedBlackTree.


<code golf>

import multi_index;
import replace;

template RBTreeZ(Value, Preds...){
    template Splat(size_t i, size_t N){
        static if(i >= N) enum Splat = "";
        else{
            enum Splat = Replace!(q{
                OrderedUnique!("a", Preds[$i]),
            }, "$i",i) ~ Splat!(i+1, N);
        }
    }
    enum ss = (Replace!( q{
        alias MultiIndexContainer!(Value,
            IndexedBy!($indeces)) RBTreeZ;
    }, "$indeces",Splat!(0,Preds.length)));
    mixin(ss);
}
void main(){
    alias RBTreeZ!(int, "a<b", "a>b") MahRBTree;
    // it compiles; good enough for me
}

</code golf>

Reply via email to