c++ - 当容器中的基本元素是 boost::tuple 时,为什么我不能使用 std::find?

标签 c++ boost

我给出以下代码使我的问题更清楚:

    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/

相关文章:

c++ - 如何与 Boost.Process 0.5 中的进程同步交互

c++ - 将两个充满数字的文件组合成第三个排序文件。文件名和 cin 的问题

c# - C++ 与 C# - 数组

c++ - Boost Djikstra 类 "boost::property_map> has no member "类型”

c++ Boost 多线程 CPU 和内存使用率缓慢且高 - 需要帮助

C++ set::find by 对象属性

c++ - 标记化 boost::regex 匹配

c++ - 自定义委托(delegate)画图在编辑时保留

c++ - 将 "pointer to data"转换为 "pointer to function"

c++ - 如何在编译期间计算数组大小(不接受指针)?