【c++11】 练习 std::bind & lambda
2016-09-08 20:02
295 查看
没事,常学习。。啦啦啦
/* *@vs2015 update3 * */ #include "stdafx.h" #include <functional> #include <vector> #include <algorithm> #include <iostream> //判断一个容器中,大于5,小于10的个数 int main() { std::vector<int> collect = {1,3,2,5,8}; auto f = std::bind(std::logical_and<bool>(), std::bind(std::greater<int>(), std::placeholders::_1, 5), std::bind(std::less_equal<int>(), std::placeholders::_1, 10)); int count = std::count_if(collect.begin(), collect.end(), f); std::cout << count << std::endl; [&collect]() { int count = 0; for (auto iter = collect.begin(); iter != collect.end(); ++iter) { if (*iter > 5 && (*iter < 10)) { count++; } } std::cout << "number: " << count << std::endl; }(); getchar(); return 0; }
相关文章推荐
- c++11 + SDL2 + ffmpeg +OpenAL + java = Android播放器
- C++11的for循环,以及范围Range类的简单实现
- C++11的新特性简单汇总介绍 (二)
- C++11的新特性简单汇总介绍 (一)
- C++11新特性之智能指针(shared_ptr/unique_ptr/weak_ptr)
- 浅析C++11中的右值引用、转移语义和完美转发
- 在 Qt4 中使用 C++11
- eclipse CDT 相关设置
- c++11新特性--decltype auto
- centos安装devtoolset-3支持gcc 4.9.2
- c++11学习笔记
- 使用eclipse编译含有C++11特性的代码
- 怎样在Linux环境编译支持C11
- eclipse支持c++11
- C++11可变参数函数与for循环
- vs2013 编译c++是发现惊天bug
- 简单性能测试函数模板
- 关于C++现状的一些思考
- 用C++11优化矩阵运算的空间和时间效率
- c++11之regex:初识regex