Opened 12 years ago

Closed 11 years ago

#5450 closed Feature Requests (worksforme)

range doesn't support circular_buffer

Reported by: anonymous Owned by: Neil Groves
Milestone: To Be Determined Component: range
Version: Boost 1.47.0 Severity: Problem
Keywords: Cc:

Description

The range library doesn't seem to specialise for circular_buffer.

Code bellow should fix the problem.

It must be placed some where' i.e. in circular_buffer' path.

Code highlighting:

#include <boost/circular_buffer.hpp>

#ifdef BOOST_PRAGMA_ONCE
#pragma once
#endif

namespace boost
{
        // Specialized metafunctions. We must include the range.hpp header.
        // We must open the 'boost' namespace.
        template< class T >
        struct range_mutable_iterator< circular_buffer<T> >
        {
                typedef typename circular_buffer<T>::iterator type;
        };

        template< class T >
        struct range_const_iterator< circular_buffer<T> >
        {
                typedef typename circular_buffer<T>::const_iterator type;
        };
        
        template<class T>
        inline typename circular_buffer<T>::iterator  
                range_begin( circular_buffer<T>& x )
        {
                return x.begin();
        }
        
        template<class T>
        inline typename circular_buffer<T>::const_iterator 
                range_begin( const circular_buffer<T>& x )
        {
                return x.begin();
        }
        
        template<class T>
        inline typename circular_buffer<T>::iterator 
                range_end( circular_buffer<T>& x )
        {
                return x.end();
        }
        
        template<class T>
        inline typename circular_buffer<T>::const_iterator
                range_end( const circular_buffer<T>& x )
        {
                return x.end();
        }

} // namespace boost

Change History (4)

comment:1 by Steven Watanabe, 12 years ago

Um. These specializations shouldn't be needed. The default implementation should work.

comment:2 by anonymous, 12 years ago

I tried using circular_buffer with ranges, it didn't work! With above code it did, so you be the judge of that.

comment:3 by Steven Watanabe, 12 years ago

I don't know what you did, but the following works for me with MSVC 2010.

#include <boost/circular_buffer.hpp>

#include <boost/range/algorithm/copy.hpp>

#include <iterator>

#include <iostream>



int main() {

        int array[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

        boost::circular_buffer<int> buf(20, array, array + 10);

        boost::copy(buf, std::ostream_iterator<int>(std::cout, "\n"));

}

Please provide: a) A small self-contained test case b) The compiler you're using c) The version of Boost you're using

comment:4 by Neil Groves, 11 years ago

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.