Search code examples
c++boostiteratoriterator-range

returning boost iterator_range from a member function


I'm trying to create a member function that returns range of an array like below:

#include <boost/range/iterator_range.hpp>

class MyClass {
public:
    boost::iterator_range< double* > range() const{ 
    boost::iterator_range< double* > itr_range = boost::make_iterator_range< double* >(&container[0], &container[m_size]);
    return itr_range;
 }
private:
    double container[4] {0.0, 1.0, 2.0, 3.0}; 
    size_t m_size = 4;
};

int main() {
   MyClass obj;   

   return 0;
}

But It gives below errors:

no matching function for call to 'make_iterator_range(const double*, const double*)' main.cpp line 6

'double*' is not a class, struct, or union type range_test      line 37, external location: /usr/include/boost/range/const_iterator.hpp 

'double*' is not a class, struct, or union type range_test      line 37, external location: /usr/include/boost/range/mutable_iterator.hpp   

required by substitution of 'template<class Range> boost::iterator_range<typename boost::range_iterator<C>::type> boost::make_iterator_range(Range&, typename boost::range_difference<Left>::type, typename boost::range_difference<Left>::type) [with Range = double*]'    range_test      line 616, external location: /usr/include/boost/range/iterator_range.hpp


 required by substitution of 'template<class Range> boost::iterator_range<typename boost::range_iterator<const T>::type> boost::make_iterator_range(const Range&, typename boost::range_difference<Left>::type, typename boost::range_difference<Left>::type) [with Range = double*]'   range_test      line 626, external location: /usr/include/boost/range/iterator_range.hpp    

What might be the problem here? Thanks in advance for your help?


Solution

  • It worked when I changed it like below:

    boost::iterator_range<const double*> range() const{ 
        return boost::make_iterator_range(&container[0], &container[m_size]);
    }