为什么我不能使用 std::find 当容器中的基本元素是 boost::tuple 时
Why I cannot use std::find when the basic element in a container is a boost::tuple?
我给出以下代码以使我的问题更清晰:
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>
相关文章:
- std::tuple默认构造函数,带有move可构造元素
- 如何在std :: tuple中的每个元素上应用constexpr函数
- 使用派生自 'std::tuple' 的元素在 'std::tuple' 上调用 'std::get' - 格式不正确
- std::tuple的实现是否允许在触发空类元素的派生到基转换时失败
- std::map<tuple<int,int>.lower_bound/upper_bound 前缀搜索,而不找到后缀的最小/最大元素
- 在运行时按索引访问 std::tuple 元素的最佳方法
- 以后可以使用分配器构造 std::tuple 的元素吗?
- 如何创建具有指定数量的元素(相同类型)的 boost::tuple
- void * 到 std::tuple 在运行时的第 n 个元素
- 将std::pair转换为具有任意数量元素的std::tuple
- 以自然(非反向)顺序将func应用于std::tuple中的元素
- 为什么 libstdc++ 以相反的顺序存储 std::tuple 元素
- 如何在编译时不知道时从 std::tuple 获取第 i 个元素?
- 访问boost::fusion::tuple中的第0个元素
- 如何通过索引设置std::tuple元素
- 对于boost::hana::tuple,元素访问的时间复杂度是多少?
- 如何获取对 std::tuple 元素的引用
- 无法使用 boost::bind 来访问 boost::tuple 元素
- 为什么我不能使用 std::find 当容器中的基本元素是 boost::tuple 时
- 如何向Boost.Tuple中添加元素