#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <bits/stl_tree.h>
using namespace std;
struct Node
{
Node(int id):id_(id) {};
struct Key
{
int operator()(const Node& node) {return node.id_;}
};
int id_;
};
struct MyCmp
{
bool operator()(int a,int b) {printf("MyCmp:%d %d\n",a,b); return a<b; }
};
template<typename K,typename V,typename KofV,typename Comp>
//class MyTree : public _Rb_tree<int,int,_Identity<int>, less<int> >
class MyTree: public _Rb_tree<K,V,KofV,Comp>
{
public:
using _Rb_tree<K,V,KofV,Comp>::_M_insert_unique;
using _Rb_tree<K,V,KofV,Comp>::iterator;
};
int main() {
//MyTree<int,int,_Identity<int>, less<int> > tree1;
MyTree<int, Node, Node::Key, less<int> > tree1;
for (int idx = 30; idx>= 0; --idx)
{
tree1._M_insert_unique( Node(idx) );
}
MyTree<int, Node, Node::Key, less<int> >::iterator it = tree1.begin();
for(; it!=tree1.end();++it)
{
printf("Tree1:%d\n", (*it).id_);
}
printf("=============test another kind of tree==========\n");
MyTree<int, Node, Node::Key, MyCmp > tree2;
for (int idx = 30; idx>= 0; --idx)
{
tree2._M_insert_unique(Node(idx));
}
MyTree<int, Node, Node::Key, MyCmp >::iterator it2 = tree2.begin();
for(; it2!=tree2.end();++it2)
{
printf("Tree2:%d\n", (*it2).id_);
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RkbGliLmg+CiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVkZSA8Yml0cy9zdGxfdHJlZS5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IE5vZGUKewoJTm9kZShpbnQgaWQpOmlkXyhpZCkge307CglzdHJ1Y3QgS2V5Cgl7CgkgICAgaW50IG9wZXJhdG9yKCkoY29uc3QgTm9kZSYgbm9kZSkge3JldHVybiBub2RlLmlkXzt9Cgl9OwoJCglpbnQgaWRfOwp9OwpzdHJ1Y3QgTXlDbXAKewoJYm9vbCBvcGVyYXRvcigpKGludCBhLGludC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