码迷,mamicode.com
首页 > 编程语言 > 详细

c++ class as sort function

时间:2018-08-09 13:52:33      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:opera   ret   span   scom   reverse   const   str   cond   compare   

// constructing sets
#include <iostream>
#include <set>
#include <string.h>


bool fncomp (int lhs, int rhs) {return lhs<rhs;}

struct classcomp {
  bool operator() (const int& lhs, const int& rhs) const
  {return lhs<rhs;}
};

int main ()
{
  std::set<int> first;                           // empty set of ints

  int myints[]= {10,20,30,40,50};
  std::set<int> second (myints,myints+5);        // range

  std::set<int> third (second);                  // a copy of second

  std::set<int> fourth (second.begin(), second.end());  // iterator ctor.

  std::set<int,classcomp> fifth(second.begin(), second.end());                 // class as Compare
  
  std::set<int>::reverse_iterator rit;
  for (rit=fifth.rbegin(); rit != fifth.rend(); ++rit)
    std::cout <<   << *rit;

  //bool(*fn_pt)(int,int) = fncomp;
  //std::set<int,bool(*)(int,int)> sixth (fn_pt);  // function pointer as Compare
  
  //std::cout<<strcmp("abc", "ab")<<std::endl;

  return 0;
}

 

c++ class as sort function

标签:opera   ret   span   scom   reverse   const   str   cond   compare   

原文地址:https://www.cnblogs.com/youge-OneSQL/p/9448184.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!