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.

39 rivejä
743 B

  1. #pragma once
  2. #include <iostream>
  3. namespace utl
  4. {
  5. namespace __impl
  6. {
  7. inline int indent_stream_index()
  8. {
  9. const int value = std::ios::xalloc();
  10. return value;
  11. }
  12. }
  13. inline std::ostream& incindent(std::ostream& os)
  14. {
  15. ++os.iword(__impl::indent_stream_index());
  16. return os;
  17. }
  18. inline std::ostream& decindent(std::ostream& os)
  19. {
  20. auto& indent = os.iword(__impl::indent_stream_index());
  21. if (--indent < 0)
  22. indent = 0;
  23. return os;
  24. }
  25. inline std::ostream& indent(std::ostream& os)
  26. {
  27. auto i = os.iword(__impl::indent_stream_index());
  28. while (i--)
  29. os << " ";
  30. return os;
  31. }
  32. }