diff --git a/src/helpers.h b/src/helpers.h index ffda72c..0635ef6 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -16,12 +16,23 @@ * Used for __str__ functions. */ template -std::string streamToString(T const & t) { +std::string streamToString(T const& t) { std::stringstream ss; ss << t; return ss.str(); } +template +std::string containerToString(T& t) { + // is there a way to make ^this const&? + // I guess not all containers have const iterators + std::stringstream ss; + for (auto const& e : t) { + ss << e << ", "; + } + return ss.str(); +} + // Be warned: Enabling something like this will break everything about Monomial, // as to Python the shared_ptr (Arg) IS the Monomial // //PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr); diff --git a/src/storage/matrix.cpp b/src/storage/matrix.cpp index 39149f8..1d03384 100644 --- a/src/storage/matrix.cpp +++ b/src/storage/matrix.cpp @@ -122,25 +122,13 @@ void define_sparse_matrix(py::module& m) { .def("__iter__", [](storm::storage::SparseMatrix::rows& rows) { return py::make_iterator(rows.begin(), rows.end()); }, py::keep_alive<0, 1>()) - .def("__str__", [](storm::storage::SparseMatrix::const_rows& rows) { - std::stringstream stream; - for (auto transition : rows) { - stream << transition << ", "; - } - return stream.str(); - }) + .def("__str__", &containerToString::rows>) ; py::class_::rows>(m, "ParametricSparseMatrixRows", "Set of rows in a parametric sparse matrix") .def("__iter__", [](storm::storage::SparseMatrix::rows& rows) { return py::make_iterator(rows.begin(), rows.end()); }, py::keep_alive<0, 1>()) - .def("__str__", [](storm::storage::SparseMatrix::const_rows& rows) { - std::stringstream stream; - for (auto transition : rows) { - stream << transition << ", "; - } - return stream.str(); - }) + .def("__str__", &containerToString::rows>) ; }