So I have successfully used the calculator example to speed a compilation of a relatively simple grammar up by about 50% (?). The calculator example can be found here. However, there was one thing in the example, which I didn't really grasp, namely calc6c.cpp:
#include "calc6c.hpp"
// This is not really called. Its only purpose is to
// instantiate the constructor of the grammar.
void instantiate_statement()
{
typedef std::string::const_iterator iterator_type;
std::vector<int> code;
statement<iterator_type> g(code);
}
I find the comment really confusing, especially, since when I tried it in my code (using my grammar) it didn't matter if such a function was included or not. I could successfully compile with and without this compilation unit. It seems to me the grammar is instantiated on ll. 74 in calc6.cpp:
typedef std::string::const_iterator iterator_type;
typedef statement<iterator_type> statement;
vmachine mach; // Our virtual machine
std::vector<int> code; // Our VM code
statement calc(code); // Our grammar
So why is the function *instantiate_statement* needed at all? Or rather: What is the difference between having a compilation unit that contains the *instantiate_statement* function as opposed to not having such a compilation unit when compiling the final program?
Also, I looked far and wide, but there doesn't seem to be a page covering this example -- or, for that matter, a more generic example of splitting up a grammar into multiple compilation units -- in greater detail and the example is completely gone in more recent incarnations of the Boost::Spirit documentation.