Variant &operator=(Variant &&v) { if(&v!=this) move_from(std::move(v)); return *this; }
void clear();
+ bool has_value() const { return funcs; }
private:
template<typename T>
DEPRECATED bool check_same_type(const Variant &v) const { return has_same_type(v); }
- bool operator==(const Variant &v) const { return (has_same_type(v) && funcs->compare(storage, v.storage)); }
+ bool operator==(const Variant &v) const;
bool operator!=(const Variant &v) const { return !(operator==(v)); }
template<typename T>
return **reinterpret_cast<T **>(storage);
}
+inline bool Variant::operator==(const Variant &other) const
+{
+ if(!funcs && !other.funcs)
+ return true;
+ else if(has_same_type(other))
+ return funcs->compare(storage, other.storage);
+ else
+ return false;
+}
+
inline bool Variant::type_equals(const Functions *funcs1, const Functions *funcs2)
{
if(!funcs1 || !funcs2)
void ref_into();
void copying();
void destruction();
+ void compare();
void types();
void mismatch();
};
add(&VariantTests::ref_into, "Reference into");
add(&VariantTests::copying, "Copying");
add(&VariantTests::destruction, "Destruction");
+ add(&VariantTests::compare, "Comparisons");
add(&VariantTests::types, "Type checks");
add(&VariantTests::mismatch, "Mismatch").expect_throw<type_mismatch>();
}
EXPECT_EQUAL(count, 0);
}
+void VariantTests::compare()
+{
+ Variant var = 1;
+ Variant var2 = 1;
+ Variant var3 = 4.2f;
+ Variant var4;
+ Variant var5;
+ EXPECT(var==var2);
+ EXPECT(var!=var3);
+ EXPECT(var!=var4);
+ EXPECT(var4==var5);
+}
+
void VariantTests::types()
{
Variant var = 42U;