我给出以下代码使我的问题更清楚:
bool bFind;
boost::tuple<int> abc;
//int abc;
std::vector<boost::tuple<int> > myArray;
//std::vector<int> myArray;
bFind = is_vector_contains(myArray,abc);
is_vector_contains 是模板函数:
template<typename T>
bool is_vector_contains(const std::vector<T> &vecArray, const T &element)
{
if(std::find(vecArray.begin(),vecArray.end(),element) == vecArray.end())
return false;
else
return true;
}
当我编译上面的代码时,出现以下编译错误:
Error 1 error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const boost::tuples::tuple<T0>' (or there is no acceptable conversion)
有什么想法吗?我尝试用这种方式定义一个相等运算符,但是没有编译成功。
bool operator == (const boost::tuple<int> &a, const boost::tuple<int> &b)
{
return true;
}
最佳答案
boost::tuple
的比较运算符在单独的 header 中定义,您必须包括:
#include <boost/tuple/tuple_comparison.hpp>
关于c++ - 当容器中的基本元素是 boost::tuple 时,为什么我不能使用 std::find?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38235037/