Compile-time reflection in C++1z? [closed]

匆匆过客 提交于 2019-11-28 21:07:27

Reflection use cases are outlined in N3814:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3814.html

The general view is that we will do it as an extension of the Type Traits library as exemplified by N3815:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3815.html

There are two parts to reflection. The first is introspection. Taking an entity and querying constant values about it. The second is reification, which is the opposite - using values to create new entities.

For introspection - you can expect additional traits that will allow you to enumerate and get the names of class members, base classes, enumerators, function paramaters and so forth at compile-time. From there you can use them for things like serialization, memberwise operations, static checks and various other things.

Additionally later we are looking at reification, which would involve creating new entities from constant values with more expressiveness than you can with a template. So perhaps you might fill out a std::class_specifier s struct and then call make_type_from_spec(s) to create the type.

The introspection approach has more consensus at the moment, the reification side is further off.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!