FC_REFLECT reflection Macro tutorial
FC_REFLECT reflection Macro tutorial 1. Background knowledge 1.1. Metalanguage and target language
Target language: a programming language that describes the final execution of a task.
Metalanguage: because the target language itself is a computer program, meta-language is a language that describes all or part of the grammatical rules of the target language.
In addition to engaging in compiler development, it is necessary to separate the meta-language from the target language, in most cases, the meta-language and the target language use the same programming language, which is easy to be confused in concept, which makes it difficult to understand the meta-language.
In C++, templates and macros are actually metalanguages.
1.2. Calculation Quadrant in Compiler Task
For most programming languages, including C++, there are four computational quadrants in the process of compiling and running
First quadrant: calculation of execution period
Second quadrant: compile-time calculation
The third quadrant: heterogeneous numerical computation
The fourth quadrant: type derivation calculation
The calculation that takes place in the first quadrant is easier to understand because it is the ultimate goal for every developer to write code.
The calculation that takes place in the second quadrant mainly includes some numerical optimizations, such as defining int axiom 2: 3; then when the first quadrant is compiled, the result is int axiom 5; where 2: 3 calculates the result directly during compilation, which is often called constant folding.
The third and fourth computational quadrants are usually abstract and related to the deduction of the template, so it is difficult to understand.
The computation that takes place in the third quadrant, called heterogeneous computing, uses different types of container objects that can be stored, such as tuple in C++. In addition, the functions used are also heterogeneous functions, which is a complex way to discuss template functions. The main thing used for this type of calculation is boost::fusion, as shown in the following example:
Auto to_string= [] (auto t) {std::stringstream ss; ss