[C++-sig] vector_indexing_suite and bool.

Prabhu Ramachandran prabhu at aero.iitm.ernet.in
Fri Aug 15 06:44:51 CEST 2003


Hi,

Thanks for the vector_indexing_suite!  It is really nice and seems to
work wonderfully!  However, I just ran into one problem with it.  I
tried wrapping a std::vector<bool> and things don't compile because
the vector_indexing_suite::get_item(...) returns a reference to the
bool which the compiler has problems with.  Here is the trivial test
program and error message that I get with g++-2.95.4 and Boost from
CVS.

// --------------------------------------------------
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>

using namespace boost::python;

BOOST_PYTHON_MODULE(vec_index)
{
    class_< std::vector<bool> > ("VectorBool")
        .def(vector_indexing_suite< std::vector<bool>, true> ());
}
// --------------------------------------------------

Compiling this produces this error:

/skratch/prabhu/cvs/boost/boost/python/suite/indexing/vector_indexing_suite.hpp: In function `static bool & boost::python::vector_indexing_suite<vector<bool,allocator<bool> >,true,boost::python::detail::final_vector_derived_policies<vector<bool,allocator<bool> >,true> >::get_item(vector<bool,allocator<bool> > &, unsigned int)':
/skratch/prabhu/cvs/boost/boost/python/suite/indexing/detail/indexing_suite_detail.hpp:410:   instantiated from `boost::python::detail::no_proxy_helper<vector<bool,allocator<bool> >,boost::python::detail::final_vector_derived_policies<vector<bool,allocator<bool> >,true>,boost::python::detail::container_element<vector<bool,allocator<bool> >,unsigned int,boost::python::detail::final_vector_derived_policies<vector<bool,allocator<bool> >,true> >,unsigned int>::base_get_item_(const boost::python::back_reference<vector<bool,allocator<bool> > &> &, PyObject *)'
/skratch/prabhu/cvs/boost/boost/python/suite/indexing/indexing_suite.hpp:200:   instantiated from `boost::python::indexing_suite<vector<bool,allocator<bool> >,boost::python::detail::final_vector_derived_policies<vector<bool,allocator<bool> >,true>,true,false,bool,unsigned int,bool>::base_get_item(boost::python::back_reference<vector<bool,allocator<bool> > &>, PyObject *)'
/skratch/prabhu/cvs/boost/boost/python/suite/indexing/indexing_suite.hpp:179:   instantiated from `boost::python::indexing_suite<vector<bool,allocator<bool> >,boost::python::detail::final_vector_derived_policies<vector<bool,allocator<bool> >,true>,true,false,bool,unsigned int,bool>::visit<boost::python::class_<vector<bool,allocator<bool> >,boost::python::detail::not_specified,boost::python::detail::not_specified,boost::python::detail::not_specified> >(boost::python::class_<vector<bool,allocator<bool> >,boost::python::detail::not_specified,boost::python::detail::not_specified,boost::python::detail::not_specified> &) const'
/skratch/prabhu/cvs/boost/boost/python/def_visitor.hpp:32:   instantiated from `boost::python::def_visitor_access::visit<boost::python::def_visitor<boost::python::indexing_suite<vector<bool,allocator<bool> >,boost::python::detail::final_vector_derived_policies<vector<bool,allocator<bool> >,true>,true,false,bool,unsigned int,bool> >, boost::python::class_<vector<bool,allocator<bool> >,boost::python::detail::not_specified,boost::python::detail::not_specified,boost::python::detail::not_specified> >(const boost::python::def_visitor<boost::python::indexing_suite<vector<bool,allocator<bool> >,boost::python::detail::final_vector_derived_policies<vector<bool,allocator<bool> >,true>,true,false,bool,unsigned int,bool> > &, boost::python::class_<vector<bool,allocator<bool> >,boost::python::detail::not_specified,boost::python::detail::not_specified,boost::python::detail::not_specified> &)'
/skratch/prabhu/cvs/boost/boost/python/def_visitor.hpp:68:   instantiated from `boost::python::def_visitor<boost::python::indexing_suite<vector<bool,allocator<bool> >,boost::python::detail::final_vector_derived_policies<vector<bool,allocator<bool> >,true>,true,false,bool,unsigned int,bool> >::visit<boost::python::class_<vector<bool,allocator<bool> >,boost::python::detail::not_specified,boost::python::detail::not_specified,boost::python::detail::not_specified> >(boost::python::class_<vector<bool,allocator<bool> >,boost::python::detail::not_specified,boost::python::detail::not_specified,boost::python::detail::not_specified> &) const'
/skratch/prabhu/cvs/boost/boost/python/class.hpp:288:   instantiated from `boost::python::class_<vector<bool,allocator<bool> >,boost::python::detail::not_specified,boost::python::detail::not_specified,boost::python::detail::not_specified>::def<boost::python::indexing_suite<vector<bool,allocator<bool> >,boost::python::detail::final_vector_derived_policies<vector<bool,allocator<bool> >,true>,true,false,bool,unsigned int,bool> >(const boost::python::def_visitor<boost::python::indexing_suite<vector<bool,allocator<bool> >,boost::python::detail::final_vector_derived_policies<vector<bool,allocator<bool> >,true>,true,false,bool,unsigned int,bool> > &)'
vec_index.cpp:9:   instantiated from here
/skratch/prabhu/cvs/boost/boost/python/suite/indexing/vector_indexing_suite.hpp:73: initializing non-const `bool &' with `_Bit_reference' will use a temporary
/skratch/prabhu/cvs/boost/boost/python/suite/indexing/vector_indexing_suite.hpp:73: warning: returning reference to temporary

I made a local copy of the vector_indexing_suite and changed this:

        static data_type& 
        get_item(Container& container, index_type i)
to:

        static data_type
        get_item(Container& container, index_type i)

and my test program compiles cleanly.  This is obviously not a fix but
just to let you know that this is the only problem.

Thanks!

cheers,
prabhu




More information about the Cplusplus-sig mailing list