

Reflection in C++14 - cylix
https://github.com/Cylix/cpp_reflection

======
sapek
There is a really interesting proposal to add reflection to the language:
N4447 [1] (N3951 before). The idea is based on an observation that C++ already
sort of has reflection-like syntax in form of parameter pack expansion [2]. I
find this approach to be a very elegant and in the spirit of modern C++. It is
also very powerful. Bond serialization is implemented using reflection.
Because C++ doesn't have reflection, for normal classes we have to use code
generation to provide type metadata. But for std::tuple<T...> all the
necessary information is already available and Bond can serialize arbitrary
instances of std::tuple<T...> today [3].

[1] [http://www.open-
std.org/jtc1/sc22/wg21/docs/papers/2015/n444...](http://www.open-
std.org/jtc1/sc22/wg21/docs/papers/2015/n4447.pdf)

[2]
[http://en.cppreference.com/w/cpp/language/parameter_pack](http://en.cppreference.com/w/cpp/language/parameter_pack)

[3]
[https://microsoft.github.io/bond/manual/bond_cpp.html#tuples](https://microsoft.github.io/bond/manual/bond_cpp.html#tuples)

~~~
jlebar
As another example, Firefox uses "manual reflection" to e.g. build lists of
all the smart pointers in some classes. It then uses these lists as part of
its "cycle collector", which breaks cycles in the refcounted graph of objects.

Writing and maintaining these lists is error-prone, and at least used to be a
major source of memory leaks. You can imagine writing a static analysis to
figure this out, and the Moz folks may have since I last checked, but if the
language could do it, that would be so much better...

~~~
pcwalton
As a somewhat-related data point, Servo is already using the macro deriving
infrastructure of Rust to generate these lists at compile time for its garbage
collector.

~~~
dman
I understand the urge to evangelise, but does Rust have to crop up in every
C++ thread?

~~~
kbenson
It was in response to a comment that was referring to Firefox. Servo is touted
as the eventual replacement of Firefox's rendering engine. It's literally a
response to a comment about Mozilla's current practices in this area
explaining their proposed future practices.

Seems appropriate to me.

------
UnknownStigma
[https://github.com/aantron/better-enums](https://github.com/aantron/better-
enums)

This is better ; P

In C++98

~~~
flaub
Similar: [https://github.com/flaub/boost-enum](https://github.com/flaub/boost-
enum)

Examples: [https://github.com/flaub/boost-
enum/blob/master/libs/test/en...](https://github.com/flaub/boost-
enum/blob/master/libs/test/enum.cpp)

