STL List 指针数据排序

来源:互联网 发布:中文域名在线转码工具 编辑:程序博客网 时间:2024/05/19 12:17

        温故知新,前段时间做FIX打包时,由于FIX包体中对各字段排序要求严格,处理时采用LIST来保存数据。

定义每个字段采用结构,保存在LIST保存的是指针。排序起来就比较有意思了。需自己实现排序方法。

       处理代码片段示例:

typedef struct stFixFieldList{  int iTag;  std::string strValue;  std::string strGrpNo;  stFixFieldList():iTag(0){}  bool operator<(const stFixFieldList& rhs)const  {    return iTag < rhs.iTag ? true : false;  }} ST_FIX_FIELD_LIST;typedef std::list<ST_FIX_FIELD_LIST *> list_FixField;template<> struct std::greater<stFixFieldList*>{  bool operator()(const stFixFieldList* a1, const stFixFieldList* a2) const  {    return *a1 < *a2;  }};
//排序处理
listFixBody.sort(std::greater<ST_FIX_FIELD_LIST*>())