ITeye博客

tuple bind

lunan · 2011-11-29 23:36 · boost · 编程语言 · Markdown

#include "stdafx.h"

 

#include <string> 

#include <iostream> 

#include <numeric>

#include <vector> 

#include <algorithm> 

#include <functional> 

#include <map>

 

#include "boost/tuple/tuple.hpp" 

#include "boost/tuple/tuple_comparison.hpp" 

#include "boost/tuple/tuple_io.hpp" 

 

#include "boost/array.hpp" 

#include "boost/assign/list_of.hpp" 

 

#include <boost/lambda/lambda.hpp>

#include <boost/lambda/bind.hpp>

using namespace boost;

 

#include <boost/bind.hpp>

 

class Person

{

public:

Person(){}

Person(const std::string& name) : name_(name){}

 

std::string& Name()

{ return name_; }

 

private:

std::string name_;

 

};

 

 

int main()

{

std::map<int, Person> persons;

persons[123] = Person("Amy");

persons[234] = Person("Ralph");

persons[345] = Person("Simon");

persons[456] = Person("Maggie");

 

//非lamad::bind 编译有问题?

std::cout << "Ralph's Id is: " << 

              std::find_if( persons.begin(), persons.end(),  

 ::lambda::bind(&Person::Name,::lambda::bind(&std::map<int, Person>::value_type::second, ::lambda::_1)) == "Ralph" )->first;

 

 

typedef boost::tuple<short,int,long> Mtuple; 

std::vector<Mtuple> vec ; 

vec= boost::assign::tuple_list_of(3,2,7)(6,2)(7,1)(5,9); 

 

 

std::cout << "bind tuple: " << 

std::find_if( vec.begin(), vec.end(), 

bind(&Mtuple::get<0>,_1) == 7 )->get<1>(); 

return 0;

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。