[英]using boost transform_iterator to std::transform conditionally
_pimpl->_connections
is a std::map
so its elements are std::pair<KeyType, gcl::SectionConnectionT*>
I want to use a Predicate gcl::SectionConnectionT::NotConnectedTo(r)
to filter out unnecessary values. _pimpl->_connections
是一个std::map
因此它的元素是std::pair<KeyType, gcl::SectionConnectionT*>
我想使用谓词gcl::SectionConnectionT::NotConnectedTo(r)
过滤掉不必要的值。 but If I use 但是如果我使用
std::remove_copy_if(it_pair.first, it_pair.second, std::back_inserter(sectionConnections), gcl::SectionConnectionT::NotConnectedTo(r));
It tries to insert the pair
into the vector. 它试图将插入
pair
到载体中。 but the vector is of type <gcl::SectionConnectionT*>
Some google search took me to transform_iterator
which I cannot understand how to understand. 但是向量的类型为
<gcl::SectionConnectionT*>
一些Google搜索将我带到了transform_iterator
,我无法理解该如何理解。 I used it like this. 我是这样用的 but getting compilations errorS
但是出现编译错误
std::pair<CollectionT::iterator, CollectionT::iterator> it_pair = _pimpl->_connections.equal_range(l);
std::vector<gcl::SectionConnectionT*> sectionConnections;
std::remove_copy_if(it_pair.first, it_pair.second, boost::make_transform_iterator(std::back_inserter(sectionConnections), util::shorthand::pair_second()), gcl::SectionConnectionT::NotConnectedTo(r));
The Boost.Iterator library is likely unable to deduce the return type of until::shorthand::pair_second::operator()(CollectionT::value_type&) const
, so the returned transform_iterator
is not modeling the Writable Lvalue Iterator concept, as is required to be used for the third parameter to std::remove_copy_if
(the output iterator). Boost.Iterator库可能无法推断
until::shorthand::pair_second::operator()(CollectionT::value_type&) const
的返回类型,因此返回的transform_iterator
并未按照要求对Writable Lvalue Iterator概念进行建模。用于std::remove_copy_if
(输出迭代器)的第三个参数。
The following works, though: 但是,以下工作原理:
//#include <boost/lambda/bind.hpp>
//#include <boost/lambda/lambda.hpp>
//#include <boost/range/adaptor/map.hpp>
//#include <boost/range/algorithm/remove_copy_if.hpp>
//namespace gcl {
//struct SectionConnectionT {
// bool NotConnectedTo(RType r) const;
// // ...
//};
//}
boost::remove_copy_if(it_pair | boost::adaptors::map_values,
std::back_inserter(sectionConnections),
boost::lambda::bind(&gcl::SectionConnectionT::NotConnectedTo, boost::lambda::_1, r));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.