Document #: | |
Date: | |
Project: | Programming Language C++ |
Reply-to: |
This paper suggests alternative keyword for reflexpr
, part of the current Reflection API1, with the aim to increase consistency and match user expectations.
Initiating reflection is currently done via the reflexpr
keyword. It could be argued, this keyword is both inconsistent with previous conventions and somewhat misleading.
We already have multiple keywords, all of which do some sort of reflection:
sizeof
- returns size of instances of a type.alignof
- returns required alignment for instances of a type.decltype
.offsetof
- returns the offset from the beginning of an object.std::addressof
- returns the address of an object.As you can see, the functions are consistent b/w each other, following the what-we-need + “of” naming scheme. There is no reason to not respect this model with the Reflection API as well.
reflexpr
“borrows” the “expr” (“expression”) suffix from constexpr
, but uses it with a different meaning:
constexpr
means “Define an expression of type constant [evaluated]”.reflexpr
means “Reflect this [expression?]”In the former case “expr” is used to define new type of expression.
In the latter case “expr” does not denote a new type of expression. It actually does not denote anything, beyond “this is a reflection [expression]”, as the argument might not be a C++ expression, strictly speaking, and the end result is just a normal (consteval) expression, not a special, “reflection” one.
Using “expr” not only creates misleading “symmetry”, one that is more confusing then helpful (it is not helpful because it does not hint at anything), but also prevents us from introducing this syntax to actually mean “reflection expression”. For example we could image reflexpr T == int
(“is same”), reflexpr A : T
(“is base of”), reflexpr A(T) || T(B)
(“constructable from”), etc. In other words, we might want to use reflexpr
to do inline reflection, without going through full reflection (meta::info).
At the moment Reflection envisions mirroring type_traits into the its own namespace. This will not remove the need for type_traits, because going back and forth b/w reflection and program code is cumbersome and verbose, probably unavoidably so.
Do not use the “expr” suffix and use “of” instead.
This way we fix both issues, stated above - we break the misleading connection to constxpr
and we increase consistency with the current facilities.
Suggested names are: reflof
(proposed), or alternatively reflectof
or reflectionof
.
Another alternative is to use “on”, simply because it matches the verb “to reflect” (on something).
reflecton
,reflon
.