我确实取得了成功。首先,我使用了以下代码:
#include <boost/xpressive/xpressive.hpp>
#include <iostream>
using namespace std;
using namespace boost::xpressive;
// A simple regular expression test
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;
}
这只是一个你好世界! https://en.wikipedia.org/wiki/%22Hello,_World!%22_program程序来自 Boost Xpressive http://www.boost.org/doc/libs/1_43_0/doc/html/xpressive/user_s_guide.html#boost_xpressive.user_s_guide.examples。首先,我编译了-H
海湾合作委员会的选项。它显示了它使用的大量标头列表。然后,我查看了 IDE 的编译标志(代码::块 https://en.wikipedia.org/wiki/Code::Blocks)正在制作并看到这样的东西:
g++ -Wall -fexceptions -g -c main.cpp -o obj/Debug/main.o
所以我写了一个命令来编译表达性.hpp具有完全相同标志的文件:
sudo g++ -Wall -fexceptions -g /usr/local/include/boost/xpressive/xpressive.hpp
我再次编译了原始代码-H
并得到这个输出:
g++ -Wall -fexceptions -H -g -c main.cpp -o obj/Debug/main.o
! /usr/local/include/boost/xpressive/xpressive.hpp.gch
main.cpp
. /usr/include/c++/4.4/iostream
.. /usr/include/c++/4.4/x86_64-linux-gnu/bits/c++config.h
.. /usr/include/c++/4.4/ostream
.. /usr/include/c++/4.4/istream
main.cpp
这 !意味着编译器能够使用预编译头。 x 表示无法使用它。使用适当的编译器标志至关重要。我取下 -H 并进行了一些速度测试。预编译头的时间从 14 秒缩短到 11 秒。不错,但也不是很好。
注意:这里是这个例子 http://www.boost.org/doc/libs/1_43_0/doc/html/xpressive/user_s_guide.html#boost_xpressive.user_s_guide.examples。我无法让它在帖子中工作。
顺便说一句:我正在使用以下g++:
g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3