#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

class finder
{
public:
    finder(const std::string &cmp_string) :s_(cmp_string){}
    bool operator ()(const std::map<int, std::string>::value_type &item)
    {
        return item.second == s_;
    }
private:
    const std::string &s_;
};



int main()
{
    map<uint32_t, string> t;
	t.insert(std::make_pair(1, "cpu_syscall_pid"));
	t.insert(std::make_pair(2, "cpu_syscall_cpu"));
	t.insert(std::make_pair(3, "cpu_syscall_sys"));
	t.insert(std::make_pair(4, "cpu_contxt_pid"));

	int n = 0;
	auto it = std::find_if(t.begin(), t.end(), finder("cpu_syscall_pid"));
    if (it != t.end())
    {
        n = (*it).first;
    }

	cout << "n:" << n << endl;
	return 0;

}

相关文章:

  • 2018-03-16
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-12
猜你喜欢
  • 2021-08-12
  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
相关资源
相似解决方案