3

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?

2 Answers 2

5

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
         >
1
  • Excellent. Spotted this late. +1, especially for submitting to boost
    – sehe
    Feb 6, 2015 at 21:28
1

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

3
  • Thank you for trying to reproduce the error. Indeed, my example code contained, another mistake (wrong parameter type in TrivialTrafo::operator()). Unfortunately, this was not the source of the problem. I've updated my question. The problem remains.
    – JohnB
    Feb 2, 2015 at 16:06
  • @JohnB Did you read my answer? I know this doesn't solve the problem. I describe the factors involved (5 minutes before your comment). I'd go read the change log/release notes or file a ticket with Boost Range :)
    – sehe
    Feb 2, 2015 at 16:08
  • Sorry, maybe bad English on my side. I know that you know it. I just wanted to clarify that correcting the mistake does not solve the problem here (VS 2010, Boost 1.57), either.
    – JohnB
    Feb 2, 2015 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.