编译时反射在C ++ 1z? [英] Compile-time reflection in C++1z?
问题描述
在C ++标准化委员会中有一个研究小组,在C ++ 1z或之后提供编译时反映。
There is a study group in the C++ standardization committee to provide compile-time reflection in C++1z or after. I would like to know what is exactly the purpose and how powerful the expected tools will be?
例如,可以使用这些工具来命名函数或类吗? / p>
For example will it be possible to name functions or classes using these tools?
struct A {int f() {return 42;}};
struct B {int (std::reflect<A>::member<0>::declname)() {return 43;}};
// equivalent to struct B {int f() {return 43;}};
如果它不像这样强大,典型的用例是什么?
If it would not be as powerful as this, what the typical use cases will be?
推荐答案
反映用例在N3814中概述:
Reflection use cases are outlined in N3814:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers /2013/n3814.html
一般来说,我们将以N3815为例来扩展Type Traits库:
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.
此外,我们正在查看reification,这将涉及创建新的实体从具有更多表达力的常量值,你可以用一个模板。所以也许你可以填写一个 std :: class_specifier s
结构,然后调用 make_type_from_spec(s)
创建类型。
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.
这篇关于编译时反射在C ++ 1z?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!