Boost logo

Boost Users :

From: Abir Basak (abirbasak_at_[hidden])
Date: 2007-11-17 14:03:33


Respected Sir,
  I am using boost::circular_buffer in my program. It uses Visual
Studio 7.1 . I am facing some problem related to iterator const
correctness, where a nonconst iterator can't be converted to const
iterator in release mode only (it works fine in debug mode)

The program demosntrates it ,
#include <boost/circular_buffer.hpp>
#include <boost/lambda/lambda.hpp>
#include <iostream>
int main(){
        using namespace boost;
        using namespace boost::lambda;
        typedef circular_buffer<int> int_buf;
        int_buf buf(3);
        buf.push_back(1);
        buf.push_back(2);
        buf.push_back(3);
        buf.push_back(4);
        int_buf::const_iterator itb = buf.begin();
        int_buf::const_iterator ite = buf.end();
        std::for_each(itb,ite,std::cout<<_1<<"\t");
}
It gives error in release mode of VS 7.1 as,
e:\boost\trunk\boost\circular_buffer\details.hpp(262): error C2248:
'boost::cb_details::iterator<Buff,Traits>::m_buff' : cannot access
private member declared in class
'boost::cb_details::iterator<Buff,Traits>'
        with
        [
            Buff=boost::circular_buffer<int>,
            Traits=boost::cb_details::nonconst_traits<std::allocator<int>>
        ]
        and
        [
            Buff=boost::circular_buffer<int>,
            Traits=boost::cb_details::nonconst_traits<std::allocator<int>>
        ]
The boost version is latest boost svn trunk download.
Apparently it seems, a friend declaration is missing, which causes the
error in iterator to const iterator conversion through iterator(const
nonconst_self& it) constructor conversion , where it tries to access
it.m_it private variable.
 My second question is, is it valid to pass a const & a non const
iterator to any function such as std::for_each, where both const
iterators are required. If I pass such thing, it gives error as
d:\Visual Studio Projects\Test\Test1.cpp(15): error C2782: '_Fn1
std::for_each(_InIt,_InIt,_Fn1)' : template parameter '_InIt' is
ambiguous
It it a valid error, or it is supposed to convert a non const iterator
to const one, and match the template parameter, if it directly doesnt
match anyone (as the conversion ctor is not explicit, I expect such
automatic conversion is possible).

thank you for such a fantastic library .

-- 
Abir Basak, Member IEEE
B. Tech , IIT KGP
Technology Lead
Software Engineer, Read Ink Technologies

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net