与升压::适配器一起使用boost ::可选::进行间接寻址 [英] Use boost::optional together with boost::adaptors::indirected
问题描述
我试图编译以下code:
I am trying to compile the following code:
#include <iostream>
#include <iterator>
#include <vector>
#include <boost/assign/std/vector.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptor/indirected.hpp>
#include <boost/range/algorithm/copy.hpp>
int main( int argc, char ** argv )
{
using namespace boost::assign;
using boost::adaptors::indirected;
std::vector<boost::optional<unsigned> > values;
values += 1u,2u,3u;
boost::copy( values | indirected, std::ostream_iterator<unsigned>( std::cout, " " ) );
std::cout << std::endl;
}
不过,我得到了一些错误,例如没有在名为
。在<一个href=\"http://www.boost.org/doc/libs/1_46_1/libs/range/doc/html/range/reference/adaptors/reference/indirected.html\">reference页面页,但是,说,单precondition是 ELEMENT_TYPE
类型boost ::可选&LT;无符号&GT; 的operator *()
一元函数的存在。有没有一种方法,使工作?
However, I got some errors, e.g. that there is no type named element_type
in boost::optional<unsigned>
. The reference page page, however, says that the single precondition is the existence of the operator*()
unary function. Is there a way to make it work?
推荐答案
这绝对是一个升压错误,但错误是否在Boost.Optional或Boost.Iterator是为辩论(我会说后者,亲自)。
This is definitely a bug in Boost, but whether that bug is in Boost.Optional or Boost.Iterator is up for debate (I would say the latter, personally).
不过,解决方法是微不足道的 - 包括任何Boost头文件之前,这样做:
However, the fix is trivial -- before including any Boost headers, do this:
#include <boost/optional/optional_fwd.hpp>
#include <boost/pointee.hpp>
namespace boost
{
template<typename P>
struct pointee<optional<P> >
{
typedef typename optional<P>::value_type type;
};
}
然后包括其他Boost头文件是必要的。
Then include other Boost headers as necessary.
请在提升Trac的,或至少发布一个bug报告在提升用户邮件列表。
Please submit a ticket on the Boost Trac, or at the least post a bug report on the Boost Users mailing list.
这篇关于与升压::适配器一起使用boost ::可选::进行间接寻址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!