Pre-compile .h files

421 Views Asked by At

I have a really short program written in boost::xpressive


#include <iostream>
#include <boost/xpressive/xpressive.hpp>

using namespace boost::xpressive;

int main()
{
    std::string hello( "hello world!" );

    sregex rex = sregex::compile( "(\\w+) (\\w+)!" );
    smatch what;

    if( regex_match( hello, what, rex ) )
    {
        std::cout << what[0] << '\n'; // whole match
        std::cout << what[1] << '\n'; // first capture
        std::cout << what[2] << '\n'; // second capture
    }

    return 0;
}

It's the Xpressive "hello world". It takes significantly longer than an ordinary hello world to compile. I think it's because the xpressive.hpp file is so huge. Is there a way to pre-compile or pre-process the .hpp file so the compile will be much faster?

1

There are 1 best solutions below

6
On BEST ANSWER

You can use precompiled headers if your compiler supports them; both g++ and Visual C++ support precompiled headers, as do most other modern C++ compilers, I suspect.