[C++-sig] vector_indexing_suite and bool.
Joel de Guzman
djowel at gmx.co.uk
Fri Aug 15 07:18:16 CEST 2003
Prabhu Ramachandran <prabhu at aero.iitm.ernet.in> wrote:
> 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> ());
> }
> // --------------------------------------------------
[snip errors]
> 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 for trying it out, Prabhu. I'll go and find a solution to
this problem. I think, off the top of my head, that get_item should be:
static typename mpl::if_<
is_class<data_type>
, data_type&
, data_type
>::type
get_item(Container& container, index_type i)
Regards,
--
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net
More information about the Cplusplus-sig
mailing list