1# C++ Static Reflection library for Thrift
2This is the C++ static reflection library for Thrift, which provides reflection support at compile-time through the use of meta-programming.
3
4
5## Usage
6Since there's no native support for static reflection in C++, Thrift will generate some metadata to ensure portability. This metadata needs to be included to enable static reflection support.
7
8Static reflection is only provided for the `cpp2` language backend, but it's backwards compatible with `cpp` through the existing `compatibility` option from `cpp2`.
9
10To direct Thrift to generate the static reflection metadata, use the `reflection` option for the `cpp2` language:
11
12```sh
13$ thrift --gen cpp2:reflection MyModule.thrift
14```
15
16Thrift breaks the metadata up in different headers to help reduce compilation times, so that a user can include only what's needed. To include this metadata in your code, include the appropriate header containing the metadata you need, as described below.
17
18Say your module is defined in `some_dir/MyModule.thrift`, these headers will be generated:
19- `some_dir/gen-cpp2/MyModule_fatal.h`: general module metadata. Necessary when using `reflect_module` and related primitives;
20- `some_dir/gen-cpp2/MyModule_fatal_types.h`: metadata for all types declared in the module, necessary when using `reflect_struct`, `reflect_enum`, `fatal::enum_traits`, `reflect_variant`, `fatal::variant_traits` and related primitives;
21- `some_dir/gen-cpp2/MyModule_fatal_all.h`: convenience header that includes all the static reflection metadata generated by the Thrift compiler.
22
23
24## Documentation
25Most documentation can be found inline in the header files under the reflection library directory.
26
27There are some demo applications unside the [`demo/` directory](demo/).
28
29There's a [video from the CppCon 2016 presentation](https://www.youtube.com/watch?v=tq0YfWFlVZA) that goes through the basics of reflection, as well as some of the [demo applications](demo/). The [accompanying slides](docs/cppcon16.pdf) with additional examples can be found in the [`docs/` directory](docs/).
30
31
32## Dependencies
33Thrift's C++ Static Reflection makes use of the [Facebook Template Library](https://github.com/facebook/fatal) to abstract most of the template meta-programming.
34
35
36# Troubleshooting
37The most common issue by far is forgetting to add some of the metadata headers generated by Thrift. Refer to the [Usage](#usage) section for more information.
38