Qt的QVariant类是否有任何现有(且方便)的访问者模式实现?
如果没有,是否有可能实现类似的东西boost::apply_visitor(),即最小化测试类型和铸造的重复?
我希望通过以下方式实现目标:
/* I have a QVariant that can contain anything, including user types */
QVariant variant;
/* But in my Visitor I'm interested only in ints and QStrings (for the sake of the example) */
struct Visitor
{
void operator()(int i) { /* do something with int */ }
void operator()(QString s) { /* ...or QString */ }
};
/* The question is: */
/* Can this be implemented in a generic way (without resorting to …Run Code Online (Sandbox Code Playgroud)