在学习rbtree时,看到第四个模板参数为class _Compare,以下为构造rbtree的几种方法
#include <iostream>
#include <bits/stl_tree.h>
#include <functional>
using namespace std;
template <class T>
struct identity : public unary_function<T, T>
{
const T &operator()(const T &x) const
{
return x;
}
};
struct Mycompare{
bool operator()(const int a,const int b){return a>b;}
};
int main()
{
_Rb_tree<int, int, identity<int>, less<int>> tree1;
auto myCompare= [](int a, int b)-> bool{ return a > b; };
_Rb_tree<int, int, identity<int>,Mycompare> tree2;
_Rb_tree<int, int, identity<int>,std::function<bool(const int a, const int b)>> rtree;
return 0;
}