预编译.h文件

时间:2010-05-08 17:07:33

标签: c++ boost compilation xpressive

我有一个用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;
}

这是Xpressive“你好世界”。编译需要比普通的hello世界更长的时间。我认为这是因为xpressive.hpp文件非常庞大。有没有办法预编译或预处理.hpp文件,以便编译速度更快?

1 个答案:

答案 0 :(得分:6)

如果您的编译器支持,您可以使用预编译的头文件;我怀疑,g++Visual C++都支持预编译头文件,就像大多数其他现代C ++编译器一样。