IODC++14 元编程增强库
IOD 库通过一个基于符号的图表增强了 C++14 元编程特性。提供一个编译时的方法来检视对象并生成匹配对象结构的代码。
支持的编译器:
-
GCC 4.9
-
Clang 3.4
示例代码:
// Define an object auto o = D(_Name = "John", _Age = 42, _City = "NYC"); // Direct access to its members. assert(o.name == "John" && o.age == 42 && o.city == "NYC"); // Static Introspection. It has no execution cost since these function // are computed at compile time. assert(o.has(_Name) == true); assert(o.has(_FirstName) == false); assert(o.has(_FirstName) == false); assert(o.size() == 3); // Output the structure of the object to std::cout: // name:John // age:42 // city:NYC foreach(o) | [] (auto& m) { std::cout << m.symbol().name() << ":" << m.value() << std::end; }
评论