C++14元编程增强库 IOD
2014年11月23日源创会年度盛典(北京站)正在报名
IOD 库通过一个基于符号的图表增强了 C++14 元编程特性。提供一个编译时的方法来检视对象并生成匹配对象结构的代码。
支持的编译器:
GCC 4.9
Clang 3.4
示例代码:
// Define an objectauto 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:NYCforeach(o) | [] (auto& m) { std::cout << m.symbol().name() << ":" << m.value() << std::end; }