boost::intrusive::sg_set使用示例
boost::intrusive是一个高效的STL容器库,在其中,sg_set作为一种无序关联容器,专门用于提供内存分配高效、空间利用率高的数据结构。下面我们来看一个sg_set的使用示例。
源代码:
#include <boost/intrusive/sg_set.hpp>
#include <iostream>
using namespace boost::intrusive;
struct MyStruct : public sg_set_base_hook< optimize_size<true> >
{
int value_;
MyStruct(int value) : value_(value) {}
friend bool operator <(const MyStruct& x, const MyStruct& y)
{ return x.value_ < y.value_; }
friend bool operator ==(const MyStruct& x, const MyStruct& y)
{ return x.value_ == y.value_; }
};
typedef sg_set<MyStruct> MySet;
typedef MySet::iterator MySetIt;
typedef MySet::const_iterator MySetCIt;
int main()
{
MySet myset;
myset.inse