std_ostream.hpp 1008 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2018-2019 Hans Dembinski
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt
  5. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_HISTOGRAM_TEST_STD_OSTREAM_HPP
  7. #define BOOST_HISTOGRAM_TEST_STD_OSTREAM_HPP
  8. #include <boost/mp11/tuple.hpp>
  9. #include <ostream>
  10. #include <utility>
  11. #include <vector>
  12. namespace std {
  13. // never add to std, we only do it here to get ADL working :(
  14. template <typename T>
  15. ostream& operator<<(ostream& os, const vector<T>& v) {
  16. os << "[ ";
  17. for (const auto& x : v) os << x << " ";
  18. os << "]";
  19. return os;
  20. }
  21. template <class... Ts>
  22. ostream& operator<<(ostream& os, const std::tuple<Ts...>& t) {
  23. os << "[ ";
  24. ::boost::mp11::tuple_for_each(t, [&os](const auto& x) { os << x << " "; });
  25. os << "]";
  26. return os;
  27. }
  28. template <class T, class U>
  29. ostream& operator<<(ostream& os, const std::pair<T, U>& t) {
  30. os << "[ " << t.first << " " << t.second << " ]";
  31. return os;
  32. }
  33. } // namespace std
  34. #endif