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
#include
#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::m_buff' : cannot access
private member declared in class
'boost::cb_details::iterator'
with
[
Buff=boost::circular_buffer<int>,
Traits=boost::cb_details::nonconst_traits
]
and
[
Buff=boost::circular_buffer<int>,
Traits=boost::cb_details::nonconst_traits
]
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