这是我的代码:
struct A{};
struct B{};
typedef std::variant<A, B> Record;
Record Get() {
return Record {A()};
}
void Test() {
if (Get() == Record{A()}) {
}
}
我收到一个错误:
在函数模板专门化'std :: __ 1 :: operator == <A,B>'的实例化中,没有匹配的函数来调用类型为'std :: __ 1 :: equal_to'的对象
为什么会出现错误,如何将函数的结果与进行比较Record{A()}
?
您需要为std::variant
可以容纳的每种类型提供相等运算符。
bool operator == (A const &lhs, A const &rhs) {
return true;
}
bool operator == (B const &lhs, B const &rhs) {
return true;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句