You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
887 B

  1. /*
  2. * helpers.h
  3. *
  4. * Created on: 16 Apr 2016
  5. * Author: harold
  6. */
  7. #ifndef PYTHON_HELPERS_H_
  8. #define PYTHON_HELPERS_H_
  9. #include <sstream>
  10. #include <string>
  11. /**
  12. * Helper function to get a string out of the stream operator.
  13. * Used for __str__ functions.
  14. */
  15. template<typename T>
  16. std::string streamToString(T const& t) {
  17. std::stringstream ss;
  18. ss << t;
  19. return ss.str();
  20. }
  21. template<typename T>
  22. std::string containerToString(T& t) {
  23. // is there a way to make ^this const&?
  24. // I guess not all containers have const iterators
  25. std::stringstream ss;
  26. for (auto const& e : t) {
  27. ss << e << ", ";
  28. }
  29. return ss.str();
  30. }
  31. // Be warned: Enabling something like this will break everything about Monomial,
  32. // as to Python the shared_ptr (Arg) IS the Monomial
  33. // //PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>);
  34. #endif /* PYTHON_HELPERS_H_ */