A replacement for std::bind2nd

前端 未结 3 894
轻奢々
轻奢々 2021-01-01 22:41

I have a foo which is a std::vector. It represents the \"edge\" values for a set of ranges.

For example, if foo is

3条回答
  •  庸人自扰
    2021-01-01 22:50

    What about going straight from Stone Age (bind2nd) to the Iron Age with a C++14 generic lambda, bypassing the Bronze Age (bind)?

    std::find_if(foo.begin(), foo.end(), [&](auto const& elem) { 
        return elem > bar; 
    }); 
    

    And if the input is sorted

    std::lower_bound(foo.begin(), foo.end(), bar); 
    

    Lambdas read much easier and are also easier to inline than std::bind expresions. See e.g. Lavevej's CppCon 2015 talk.

提交回复
热议问题