为什么boost :: variant不提供operator!= [英] Why does boost::variant not provide operator !=
问题描述
给定两个完全相同的 boost :: variant
实例 a
code> b ,则允许使用表达式 (a == b)
/ p>
但 (a!= b)
似乎未定义。为什么是这样?
我认为它只是没有添加到库中。 Boost.Operators不会真正帮助,因为任一变体都将从boost :: operator :: equality_comparable派生。 David Pierre是正确的说你可以使用它,但是你的回答也是正确的,新的操作符!=将不能被ADL找到,所以你需要一个使用操作符。
我会在boost-users邮件列表中询问这个。
从@ AFoglia的注释编辑:
七个月后,我正在学习Boost.Variant,我对这个更好的解释列出了遗漏列表。
http://boost.org/Archives/boost/2006/06/105895.php
操作符==
调用 operator ==
当前在变体中的实际类。同样,调用 operator!=
也应该调用类的 operator!=
。 (因为理论上可以定义一个类,所以 a!= b
不等于!(a == b)
。)因此,这将增加另一个要求变量中的类有一个 operator!=
。 (有一个关于你是否可以在邮件列表线程中做这个假设的争论。)
Given two identical boost::variant
instances a
and b
, the expression ( a == b )
is permitted.
However ( a != b )
seems to be undefined. Why is this?
I think it's just not added to the library. The Boost.Operators won't really help, because either variant would have been derived from boost::operator::equality_comparable. David Pierre is right to say you can use that, but your response is correct too, that the new operator!= won't be found by ADL, so you'll need a using operator.
I'd ask this on the boost-users mailing list.
Edit from @AFoglia's comment:
Seven months later, and I'm studying Boost.Variant, and I stumble over this better explanation of the omission lists.
http://boost.org/Archives/boost/2006/06/105895.php
operator==
calls operator==
for the actual class currently in the variant. Likewise calling operator!=
should also call operator!=
of the class. (Because, theoretically, a class can be defined so a!=b
is not the same as !(a==b)
.) So that would add another requirement that the classes in the variant have an operator!=
. (There is a debate over whether you can make this assumption in the mailing list thread.)
这篇关于为什么boost :: variant不提供operator!=的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!