[英]Can't compile this Boost Algorithm example on GCC
#include <boost/algorithm/string.hpp>
#include <vector>
#include <iostream>
#include <string>
using namespace std;
using namespace boost;
int main(int, char **)
{
string test = "h:help";
vector<string> v;
iter_split(v, test, first_finder("h:"));
copy(v.begin(), v.end(), ostream_iterator<string>(cout, "\n"));
return 0;
}
This simple code will not compile in GCC 4.6 using -std=c++0x
; 这个简单的代码不能使用
-std=c++0x
在GCC 4.6中编译; it will, however, compile fine in both an older compiler (4.2) and without the C++0x mode. 但是,它将在较旧的编译器(4.2)和没有C ++ 0x模式下编译良好。
The error message output is: 错误消息输出是:
In file included from /usr/include/boost/algorithm/string/split.hpp:15:0,
from /usr/include/boost/algorithm/string.hpp:22,
from test.cpp:1:
/usr/include/boost/algorithm/string/iter_find.hpp: In function 'SequenceSequenceT& boost::algorithm::iter_split(SequenceSequenceT&, RangeT&, FinderT) [with SequenceSequenceT = std::vector<std::basic_string<char> >, RangeT = std::basic_string<char>, FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>]':
test.cpp:15:47: instantiated from here
/usr/include/boost/algorithm/string/iter_find.hpp:154:51: error: call of overloaded 'end(std::basic_string<char>&)' is ambiguous
/usr/include/boost/algorithm/string/iter_find.hpp:154:51: note: candidates are:
/usr/include/boost/range/end.hpp:145:56: note: typename boost::range_iterator<typename boost::remove_const<T>::type>::type boost::end(T&) [with T = std::basic_string<char>, typename boost::range_iterator<typename boost::remove_const<T>::type>::type = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]
/usr/include/boost/range/end.hpp:156:61: note: typename boost::range_const_iterator<C>::type boost::end(const T&) [with T = std::basic_string<char>, typename boost::range_const_iterator<C>::type = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >]
/usr/lib/gcc/i686-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/range_access.h:78:5: note: decltype (__cont.end()) std::end(const _Container&) [with _Container = std::basic_string<char>, decltype (__cont.end()) = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >]
/usr/lib/gcc/i686-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/range_access.h:68:5: note: decltype (__cont.end()) std::end(_Container&) [with _Container = std::basic_string<char>, decltype (__cont.end()) = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]
test.cpp:15:47: instantiated from here
/usr/include/boost/algorithm/string/iter_find.hpp:162:39: error: call of overloaded 'begin(std::basic_string<char>&)' is ambiguous
/usr/include/boost/algorithm/string/iter_find.hpp:162:39: note: candidates are:
/usr/include/boost/range/begin.hpp:146:64: note: typename boost::range_iterator<typename boost::remove_const<T>::type>::type boost::begin(T&) [with T = std::basic_string<char>, typename boost::range_iterator<typename boost::remove_const<T>::type>::type = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]
/usr/include/boost/range/begin.hpp:157:61: note: typename boost::range_const_iterator<C>::type boost::begin(const T&) [with T = std::basic_string<char>, typename boost::range_const_iterator<C>::type = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >]
/usr/lib/gcc/i686-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/range_access.h:58:5: note: decltype (__cont.begin()) std::begin(const _Container&) [with _Container = std::basic_string<char>, decltype (__cont.begin()) = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >]
/usr/lib/gcc/i686-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/range_access.h:48:5: note: decltype (__cont.begin()) std::begin(_Container&) [with _Container = std::basic_string<char>, decltype (__cont.begin()) = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]
Could this be a bug in GCC? 这可能是海湾合作委员会的一个错误吗? Or is there something I could do to the code to fix this?
或者我可以对代码做些什么来解决这个问题?
Ensure that you have installed boost-devel package 确保已安装boost-devel软件包
In Centos execute as root: 在Centos中以root身份执行:
yum install boost-devel
then 然后
root@centos6 /]# find / -name boost
/usr/include/boost
/usr/lib64/boost
[root@centos6 /]#
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.