(boost / Algorithm / stringライブラリから)と一緒にstd::find_if
使用して述語を作成しようとしています。次のスニペットは、私がこれを達成しようとしている2つの方法を示しています。boost::bind
boost::contains
#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 << s1 << " contains " << "hello, " << std::boolalpha << contain_hello(s1) << std::endl;
std::cout << s2 << " contains " << "hello, " << std::boolalpha << contain_hello(s2) << std::endl;
return EXIT_SUCCESS;
}
このコードをg++3.4.5でコンパイルすると、次の出力が得られます。
error: conversion from `<unresolved overloaded function type>' to non-scalar type `boost::function<bool ()(std::string, std::string), std::allocator<void> >' requested
error: no matching function for call to `bind(<unresolved overloaded function type>, boost::arg<1>&, std::string)'
boost::icontains
オーバーロードが1つしかないものに切り替えると、すべてが正常に機能します。非テンプレート関数のオーバーロードが複数ある場合に、同様の状況を解決する方法を知っています。誰かが私がこれを正しく書くのを手伝ってもらえますか?または、独自の比較関数を作成する必要がありますか?