我有一个用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 world”。编译所需的时间比普通的hello世界长得多。我认为是因为xpressive.hpp文件太大。有没有办法预编译或预处理.hpp文件,这样编译会快得多?
最佳答案
如果编译器支持预编译头,则可以使用它们。我怀疑g++和Visual C++都支持预编译的 header ,就像大多数其他现代C++编译器一样。