最好的方法来测试两个valarray< double> [英] Best way to test for equality of two valarray<double>?

查看:170
本文介绍了最好的方法来测试两个valarray< double>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为 == valarray 的默认重载不是很方便。默认情况下 x == y (对于两个valarrays x和y)返回 valarray 如果 x [i] == y [i] ,则 i c $ c>。相反,我需要一个 bool ,它告诉我如果 valarray< double> 包含相同的元素。我知道我可以做一个周期,但必须做的周期每次都不方便。这里最好的解决方法是什么?有没有办法为我定义自己的重载 == (还有!= ,<$ c $

I think that the default overload of == for valarray is not very convenient. By default x==y (for two valarrays x and y) returns a valarray<bool>, with true on the ith entry if x[i]==y[i]. Rather, I need a single bool, which tells me if both valarray<double> contain the same elements or not. I know I can do this with a cycle, but having to do the cycle every time is not convenient. What's the best workaround here? Is there a way for me to define my own overload of == (and also !=, <, and so on)?

推荐答案

不是很方便?这个行为正是为 valarray 的原因。

"Not very convenient"? This behaviour is exactly the reason for valarray.

要覆盖它将是完全自我毁灭的。

To override it would be entirely self-defeating.

如果你不喜欢,只需使用向量

If you don't like it, just use a vector instead.

这篇关于最好的方法来测试两个valarray&lt; double&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆