我正在尝试编译以下代码:
#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;
}
但是,我遇到了一些错误,例如没有名为的类型element_type
in boost::optional<unsigned>
. The 参考页 http://www.boost.org/doc/libs/1_46_1/libs/range/doc/html/range/reference/adaptors/reference/indirected.html然而,页面说,唯一的前提条件是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;
};
}
然后根据需要包含其他 Boost 标头。
请在升压追踪 https://svn.boost.org/trac/boost/,或者至少在上发布错误报告提升用户邮件列表 http://lists.boost.org/mailman/listinfo.cgi/boost-users.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)