Advertisement
dooly386

boost::intrusive::rbtree< X<double> > tree;

May 11th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. template <typename T>
  2. struct X  : public boost::intrusive::set_base_hook<boost::intrusive::store_hash<true> >
  3. {
  4.     X(T x) : _x{x} { }
  5.  
  6.     T _x;
  7.  
  8.     std::ostream& operator<<( std::ostream& os) const
  9.     {
  10.         os << _x;
  11.         return os;
  12.     }
  13.  
  14.     bool operator<(const X& rhs) const { return _x < rhs._x; }
  15.     bool operator>(const X& rhs) const { return _x > rhs._x; }
  16.     bool operator==(const X& rhs) const { return _x == rhs._x; }
  17.  
  18. };
  19.  
  20.  
  21.  
  22. void __fastcall TTestForm::Button1Click(TObject *Sender)
  23. {
  24.     std::vector<X<double>> list;
  25.     for(int i=0;i<10000;i++)
  26.     {
  27.         X<double> x(i);
  28.         list.push_back(x);
  29.  
  30.     }
  31.  
  32.     boost::intrusive::rbtree< X<double> > tree;
  33.     tree.insert_unique(list.begin(),list.end());
  34.     boost::intrusive::rbtree< X<double> >::iterator loit = tree.lower_bound(X<double>(10));
  35.     boost::intrusive::rbtree< X<double> >::iterator upit = tree.upper_bound(X<double>(13));
  36.  
  37.     boost::intrusive::rbtree< X<double> >::iterator it;
  38.     for(it = loit;it!=upit;++it)
  39.     {
  40.  
  41.         Memo1->Lines->Add((*it)._x);
  42.     }
  43.  
  44.  
  45. }
  46. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement