diff --git a/include/boost/python/suite/indexing/testsuite.cpp b/include/boost/python/suite/indexing/testsuite.cpp index 426b3e0d..758462dc 100755 --- a/include/boost/python/suite/indexing/testsuite.cpp +++ b/include/boost/python/suite/indexing/testsuite.cpp @@ -22,46 +22,76 @@ // #include "container_suite.hpp" +#include "IntWrapper.hpp" #include #include #include +#include +#include + #include #include #include +#include #include "iterator_pair.hpp" -indexing::iterator_pair getArray() +indexing::iterator_pair getArray() { - static int array[] = { 8, 7, 6, 5, 4, 3, 2, 1, 0 }; + static IntWrapper array[] = { + IntWrapper(8), IntWrapper(7), IntWrapper(6), IntWrapper(5) + , IntWrapper(4), IntWrapper(3), IntWrapper(2) + , IntWrapper(1), IntWrapper(0) }; - return indexing::iterator_pair(indexing::begin(array) - , indexing::end(array)); + return indexing::iterator_pair(indexing::begin(array) + , indexing::end(array)); +} + +std::string repr (IntWrapper const &i) +{ + std::stringstream temp; + temp << i; + return temp.str(); } BOOST_PYTHON_MODULE(testsuite) { + boost::python::implicitly_convertible (); + + boost::python::class_ ("IntWrapper", boost::python::init()) + .def ("increment", &IntWrapper::increment) + .def ("__repr__", repr); + ; + typedef std::vector Container1; boost::python::class_("Vector") - .def (indexing::container_suite()); + .def (indexing::container_suite::generate()); - typedef std::list Container2; + typedef std::list Container2; boost::python::class_("List") - .def (indexing::container_suite()); + .def (indexing::container_suite::generate()); - typedef std::map Container3; + typedef std::map Container3; boost::python::class_("Map") - .def (indexing::container_suite()); + .def (indexing::container_suite::generate()); - typedef indexing::iterator_pair Container4; + typedef indexing::iterator_pair Container4; - boost::python::class_("Array" - , boost::python::init()) - .def (indexing::container_suite()); + boost::python::class_ + ("Array", boost::python::init()) + .def (indexing::container_suite::generate()); boost::python::def ("getArray", getArray); + + typedef std::vector Container5; + + // Returning internal references to elements of a vector is + // dangerous! The references can be invalidated by inserts or + // deletes! + boost::python::class_("Vector_ref") + .def (indexing::container_suite::generate (boost::python::return_internal_reference<>())); }