Rup*_*nes 9 c++ boost boost-optional
我正在尝试编译以下代码:
#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;
}
Run Code Online (Sandbox Code Playgroud)
但是,我得到了一些错误,例如没有命名的类型element_type在boost::optional<unsigned>.该参考页页,但是,说,单前提条件是存在operator*()一元函数.有没有办法让它发挥作用?
这绝对是Boost中的一个错误,但是这个错误是否在Boost.Optional或Boost.Iterator中有争议(我会说后者,个人).
但是,修复是微不足道的 - 在包含任何Boost标头之前,请执行以下操作:
#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;
};
}
Run Code Online (Sandbox Code Playgroud)
然后根据需要包含其他Boost标头.
请在Boost Trac上提交一张票,或者至少在Boost Users邮件列表上发布一个错误报告.
| 归档时间: |
|
| 查看次数: |
1143 次 |
| 最近记录: |