有人能告诉我为什么我在下面代码的最后一行出现编译器错误?Boost:使用apply_visitor比较变体
注:如果我删除以下行,我的代码被没有错误编译:
appliedEqualityVisitor(compareValue);
下面是代码:
#include "boost/variant/variant.hpp"
#include "boost/variant/apply_visitor.hpp"
using namespace std;
using namespace boost;
template<typename T>
struct CheckOneTypeEquality : public boost::static_visitor<>
{
T const* value;
bool operator()(T const& other) const
{
return other == *value;
}
template<typename U>
bool operator()(U const& other) const
{
return false;
}
CheckOneTypeEquality(T const& value_):value(&value_) {}
};
typedef variant<int, string> MyVariant;
typedef apply_visitor_delayed_t<CheckOneTypeEquality<MyVariant>> AppliedEqualityVisitorType;
int main(int argc, char **argv)
{
int testValue = 12;
CheckOneTypeEquality<MyVariant> equalityVisitor(testValue);
AppliedEqualityVisitorType appliedEqualityVisitor = apply_visitor(equalityVisitor);
MyVariant compareValue = 13;
appliedEqualityVisitor(compareValue); // <<<<< compile error here
return 0;
}
发生时错误的升压例子吗? –
@Meysam boost :: variant提供'operator ==',因此可以使用'operator =='比较同一个变体的两个实例,前提是每个有界类型都符合EqualityComparable概念 – mark
@mark你是对的。我有点误导了! – Meysam