`
lunan
  • 浏览: 77979 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

tuple bind

 
阅读更多

#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;

}

分享到:
评论

相关推荐

    C++ STL 内 std::{bind/tuple/function} 简单实现

    在C++标准库STL中,`std::bind`、`std::tuple`和`std::function`是非常重要的工具,它们提供了高级的函数操作和参数管理能力。下面将详细解释这三个概念及其简单实现的关键点。 首先,我们来看`std::function`。`...

    c++标准库扩展 TR1

    在TR1中,`std::tr1`命名空间引入了一系列重要的工具类,如`shared_ptr`、`function`、`bind`、`mem_fn`以及`tuple`等。 #### `shared_ptr` `shared_ptr`是一种智能指针,用于管理动态分配的对象的生命周期。通过...

    python通过tkinter的选择框的应用

    comboGrade = tkinter.ttk.Combobox(root, width=50, values=tuple(studentClasses.keys())) ``` 在上面的代码中,我们创建了一个选择框,名称为 `comboGrade`,宽度为 50 个字符,并将其值设置为 `studentClasses` ...

    c++实用软件包(utility.h)

    `utility`中还有一些预定义的类型别名,如`std::tuple_size`, `std::tuple_element`等,它们用于元编程,处理`std::tuple`对象。 8. **模板元编程(Template Metaprogramming)** 虽然`utility`不直接涉及模板元...

    c++2005教程

    - **`tr1::tuple`**: 类似于C++11的`std::tuple`,用于存储异构数据集,可以存储不同类型的元素。 - **`tr1::unordered_map` 和 `tr1::unordered_set`**: 提供了基于哈希表的数据结构,提供了快速的插入、查找和...

    boost 1.41 中文文档,使用帮助,教程手册

    fatalerror99 array, bind & mem_fn, dynamic_bitset, function, functional/hash, in_place_factory & typed_in_place_factory, lambda, ref, smart_ptr, static_assert, string_algo, type_traits, typeof ...

    Python基于stuck实现scoket文件传输

    使用socket中的struck来实现客户端发送 服务端:  客户端: # -*- coding: UTF-8 -*- ...s.bind((host, port)) # 绑定需要监听的Ip和端口号,tuple格式 s.listen(1) def conn_thread(connection,

    THE BOOST C++ LIBRARIES

    3.2 Boost.Bind 3.3 Boost.Ref 3.4 Boost.Function 3.5 Boost.Lambda 3.6 Exercises Chapter 4: Event Handling 4.1 General 4.2 Signals 4.3 Connections 4.4 Exercises Chapter 5: String Handling 5.1 General ...

    超越C++标准库-boost程序库导论

    - **Tuple**:提供了一种将多个值组合在一起的方式,每个位置上的元素可以是不同的类型。 #### Bind库 - **Bind**:支持将函数或成员函数与部分参数绑定。 #### Lambda库 - **Lambda**:允许创建临时函数对象,...

    boost_1_34_0的包含文件(boost目录下的全部文件)

    Boost库的核心目标是推动C++标准的发展,并且很多Boost库最终被纳入到了C++标准库中,例如`shared_ptr`、`unique_ptr`、`bind`、`lambda`、`variant`和`tuple`等。下面将详细探讨一些在`boost_1_34_0`中重要的库和...

    cpp11_Make_life_easier.pdf

    比如`auto Get()-&gt;decltype(std::tie(age,name))`,它自动推导`Get`函数返回类型为`std::tuple, std::string&gt;`。 接着,文档探讨了C++11中`lambda`表达式的使用,它为编写匿名函数提供了极大的便利。相较于传统的...

    STL.rar_STL

    例如,`std::less`和`std::greater`用于比较元素,`std::bind1st`和`std::bind2nd`用于绑定函数参数。 4. **算法**:STL包含了一整套强大的算法库,如排序(sort)、查找(find)、复制(copy)、合并(merge)、...

    计算机网络第六版答案

    Computer Networking: A Top-Down Approach, 6th Edition Solutions to Review Questions and Problems Version Date: May 2012 ...This document contains the solutions to review questions and problems for...

    C++标准库Boost程序库导论

    Boost在这一领域也贡献颇多,其中最为人熟知的是`boost::array`、`boost::multi_array`、`boost::tuple`、`boost::variant`等容器。这些容器提供了更灵活的选择,比标准库中的容器更加多样化,能够满足不同场景下的...

    C++标准2003C++标准2003

    此外,还引入了`std::tr1`,这是对C++标准库的扩展,包含了如`shared_ptr`、`weak_ptr`等智能指针,以及函数对象绑定器`bind`和`tuple`等新组件,为泛型编程提供了更多支持。 再者,C++2003标准对模板进行了扩展,...

    CLR via C# 3rd Edition

    新增了关于如何部署包含内嵌依赖程序集的单一文件的一节,以及比较反射调用、bind/invode、bind/create、delegate/invoke、C#动态类型的一节。 Chapter 24-Runtime Serialization 全新的一章。 Part V – ...

Global site tag (gtag.js) - Google Analytics