- 论坛徽章:
- 44
|
本帖最后由 windoze 于 2015-07-06 15:58 编辑
回复 29# yulihua49
如果你能把数据类型限制在有限的几个种类,用type switch能简单点。
比如:
- // @SEE: https://github.com/windoze/cxxstuff
- #include <cxutil/variant.hpp>
- typedef cxutil::variant<int,double,std::string> DBVariant;
- struct RDB_set_col_visitor {
- RDB_insert_visitor(DB_cursor *cursor, String column);
- int operator()(int x) &&;
- int operator()(double x) && ;
- int operator()(const std::string &x) &&;
- };
- DBVariant var(123.45);
- var.apply_visitor(RDB_set_col_visitor(cursor, "some_col"));
复制代码 不过你想把一个struct直接映射到一个Row还是没什么好办法。
C++目前完全没有任何办法遍历任意一个struct的成员,所以我在想用clang的compiler plugin写个代码生成器,实现类似Rust的Macro的功能。
|
|