小编lol*_*nus的帖子

如何为boost :: bind强制模板函数重载?

我正在尝试std::find_if通过boost::bindboost::contains(来自boost/algoritm/string库)一起使用来创建谓词.以下片段显示了我试图完成此任务的两种方式.

#include <boost/algorithm/string.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>

#include <iostream>
#include <string>

int main(int argc, char** argv) {
        std::string s1("hello mom");
        std::string s2("bye mom");

        boost::function<bool (std::string, std::string)> f = &boost::contains<std::string, std::string>;
        std::cout << s1 << " contains " << "hello, " << std::boolalpha << f(s1, "hello") << std::endl;
        std::cout << s2 << " contains " << "hello, " << std::boolalpha << f(s2, "hello") << std::endl;

        boost::function<bool (std::string)> contain_hello = boost::bind(boost::contains<std::string, std::string>, _1, std::string("hello"));
        std::cout << …
Run Code Online (Sandbox Code Playgroud)

c++ templates overloading boost-bind boost-function

5
推荐指数
1
解决办法
3925
查看次数

标签 统计

boost-bind ×1

boost-function ×1

c++ ×1

overloading ×1

templates ×1