我有一个声明为class MyClass : public list_base_hook<link_mode<normal_link>>
. 我还有一个声明为list<MyClass> global_list_MyClass
.
global_list_MyClass
我使用 for 循环插入 10 个节点。我的目标是尝试交换Node1
和Node2
使用boost::intrusive::swap
,但似乎失败了(很多编译错误)。
我试图在互联网上搜索,但找不到任何好的例子。
示例代码:
class MyClass : public list_base_hook<link_mode<normal_link>>
{
public:
int nValue;
public:
MyClass(){}
virtual ~MyClass(){}
};
static boost::intrusive::list<MyClass> global_list_MyClass;
//Insert 10 nodes
for (int n=0; n<10; n++)
{
MyClass *p_oTMP1 = new MyClass();
p_oTMP1->nValue = n;
global_list_MyClass.push_back(*p_oTMP1);
}
//Search for Target node 1
int nTarget1 = 5;
boost::intrusive::list<MyClass>::iterator oTmpTarget1;
for (list<MyClass>::iterator iTmpToken=global_list_MyClass.begin(); iTmpToken!=global_list_MyClass.end(); iTmpToken++)
{
if (!(iTmpToken->nValue == nTarget1))
continue;
oTmpTarget1 = iTmpToken;
break;
}
//Search for Target node 2
int nTarget2 = 6;
boost::intrusive::list<MyClass>::iterator oTmpTarget2;
for (list<MyClass>::iterator iTmpToken=global_list_MyClass.begin(); iTmpToken!=global_list_MyClass.end(); iTmpToken++)
{
if (!(iTmpToken->nValue == nTarget2))
continue;
oTmpTarget2 = iTmpToken;
break;
}
//Swap Node1 with Node2
/*Here is what i not sure what to do with boost::intrusive::swap or global_list_MyClass.swap()