Reputation: 13713
The following does not compile on Visual Studio 2010:
std::vector<int> v;
for (int i = 0; i < 10; ++i) v.push_back (i);
struct TrivialTrafo {
typedef int result_type;
int operator () (int i) const { return 1; }
};
auto x = v | boost::adaptors::transformed (TrivialTrafo ())
| boost::adaptors::strided (2);
The compiler complains (error message originally in German, my translation):
error C2664:
'boost::range_detail::strided_iterator<BaseIterator,Category>::strided_iterator
(const boost::range_detail::strided_iterator<BaseIterator,Category> &)':
Conversion of parameter 1 from
'boost::range_detail::strided_iterator<BaseIterator,Category>' into
'const boost::range_detail::strided_iterator<BaseIterator,Category> &'
not possible
with
[
BaseIterator=boost::iterators::transform_iterator<
TEST_rectnew_getRows::TrivialTrafo,std::_Vector_iterator<
std::_Vector_val<int,std::allocator<int>>>>,
Category=boost::iterators::detail::iterator_category_with_traversal<
std::input_iterator_tag,boost::iterators::random_access_traversal_tag>
]
and
[
BaseIterator=boost::iterators::transform_iterator<
TEST_rectnew_getRows::TrivialTrafo,std::_Vector_iterator<
std::_Vector_val<int,std::allocator<int>>>>,
Category=boost::iterators::random_access_traversal_tag
]
and
[
BaseIterator=boost::iterators::transform_iterator<
TEST_rectnew_getRows::TrivialTrafo,
std::_Vector_iterator<std::_Vector_val<int,std::allocator<int>>>
>,
Category=boost::iterators::detail::iterator_category_with_traversal<
std::input_iterator_tag,boost::iterators::random_access_traversal_tag>
]
I'm using Boost 1.57.
Obviously operator |
tries to construct a strided_range
with the wrong Category
template parameter value?
Is this a bug, or am I doing anything wrong?
Upvotes: 3
Views: 362
Reputation: 157354
Yeah, it's a bug in Neil Groves' rewrite of strided.hpp
(since 1.56, so you could revert to that version of boost if you need to). I've submitted a ticket: https://svn.boost.org/trac/boost/ticket/10989
One-line fix:
--- a/include/boost/range/adaptor/strided.hpp
+++ b/include/boost/range/adaptor/strided.hpp
@@ -603,7 +603,7 @@ namespace boost
template<
class Rng,
class Category =
- typename iterator_traversal<
+ typename iterators::pure_iterator_traversal<
typename range_iterator<Rng>::type
>::type
>
Upvotes: 5
Reputation: 393064
I think you're confused. It actually works fine:
#include <boost/range/adaptors.hpp>
#include <iostream>
struct TrivialTrafo {
typedef int result_type;
int operator () (int i) const { return i; }
};
int main()
{
std::vector<int> v;
for (int i = 0; i < 10; ++i) v.push_back (i);
for (auto&& x : v | boost::adaptors::transformed (TrivialTrafo ())
| boost::adaptors::strided (2))
{
std::cout << x << " ";
}
}
Prints
0 2 4 6 8
Looks like you expected the transformation to take an iterator instead of the range's value type?
UPDATE Ah, it might be a regression/change in the Boost Range library, since it doesn't compile Live On Coliru
This means it does work with Boost 1.55, but not with whatever Coliru uses:
http://coliru.stacked-crooked.com/a/f7a2ee559e0cf008 says that's 1.57
Upvotes: 1