forked from parallel101/course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprinter.h
33 lines (27 loc) · 811 Bytes
/
printer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once
#include <iostream>
#include <utility>
#include <type_traits>
namespace std {
template <class T, class = const char *>
struct __printer_test_c_str {
using type = void;
};
template <class T>
struct __printer_test_c_str<T, decltype(std::declval<T>().c_str())> {};
template <class T, int = 0, int = 0, int = 0,
class = decltype(std::declval<std::ostream &>() << *++std::declval<T>().begin()),
class = decltype(std::declval<T>().begin() != std::declval<T>().end()),
class = typename __printer_test_c_str<T>::type>
std::ostream &operator<<(std::ostream &os, T const &v) {
os << '{';
auto it = v.begin();
if (it != v.end()) {
os << *it;
for (++it; it != v.end(); ++it)
os << ',' << *it;
}
os << '}';
return os;
}
}