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

Why I cannot use std::find when the basic element in a container is a boost::tuple?

本文关键字:元素 tuple boost 不能 std 为什么 find      更新时间:2023-10-16

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

    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 的比较运算符定义在一个单独的标头中,您必须包括:

#include <boost/tuple/tuple_comparison.hpp>