最好的方法来测试两个valarray< double> [英] Best way to test for equality of two 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 i
th 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< double>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!