小编Mit*_*dir的帖子

Lambdas和std :: function

我正在努力追赶C++ 11和所有出色的新功能.我对lambdas有点困惑.

这是我能够开始工作的代码:

#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <functional>

using namespace std;

template<typename BaseT, typename Func>
vector<BaseT> findMatches(vector<BaseT> search, Func func)
{
    vector<BaseT> tmp;

    for(auto item : search)
    {
        if( func(item) )
        {
            tmp.push_back(item);
        }
    }

    return tmp;
}

void Lambdas()
{
    vector<int> testv = { 1, 2, 3, 4, 5, 6, 7 };

    auto result = findMatches(testv, [] (const int &x) { return x % 2 == 0; });

    for(auto i : result)
    {
        cout …
Run Code Online (Sandbox Code Playgroud)

c++ lambda templates c++11

4
推荐指数
1
解决办法
2208
查看次数

标签 统计

c++ ×1

c++11 ×1

lambda ×1

templates ×1