|
| 1 | +#ifndef FAKE_IOSTREAM_H |
| 2 | +#define FAKE_IOSTREAM_H |
| 3 | + |
| 4 | +#include <cstdio> |
| 5 | +#include <string> |
| 6 | +#include <string_view> |
| 7 | + |
| 8 | +namespace fake { |
| 9 | + |
| 10 | +struct ostream {}; |
| 11 | + |
| 12 | +static ostream cout; |
| 13 | + |
| 14 | +inline ostream& operator<<(ostream& os, char c) { |
| 15 | + fputc(c, stdout); |
| 16 | + return os; |
| 17 | +} |
| 18 | + |
| 19 | +inline ostream& operator<<(ostream& os, const char* x) { |
| 20 | + printf("%s", x); |
| 21 | + return os; |
| 22 | +} |
| 23 | + |
| 24 | +inline ostream& operator<<(ostream& os, const std::string& x) { |
| 25 | + printf("%s", x.c_str()); |
| 26 | + return os; |
| 27 | +} |
| 28 | + |
| 29 | +inline ostream& operator<<(ostream& os, const std::string_view& x) { |
| 30 | + fwrite(x.data(), sizeof(char), x.size(), stdout); |
| 31 | + return os; |
| 32 | +} |
| 33 | + |
| 34 | +inline ostream& operator<<(ostream& os, bool b) { |
| 35 | + #if 0 |
| 36 | + fputc(b ? '1' : '0', stdout); |
| 37 | + #else |
| 38 | + os << (b ? "true" : "false"); |
| 39 | + #endif |
| 40 | + return os; |
| 41 | +} |
| 42 | + |
| 43 | +inline ostream& operator<<(ostream& os, void const * x) { |
| 44 | + printf("%p", x); |
| 45 | + return os; |
| 46 | +} |
| 47 | + |
| 48 | +inline ostream& operator<<(ostream& os, void const volatile * x) { |
| 49 | + printf("%p", (void const*)x); |
| 50 | + return os; |
| 51 | +} |
| 52 | + |
| 53 | +inline ostream& operator<<(ostream& os, nullptr_t) { |
| 54 | + printf("%p", nullptr); |
| 55 | + return os; |
| 56 | +} |
| 57 | + |
| 58 | +inline ostream& operator<<(ostream& os, int x) { |
| 59 | + printf("%d", x); |
| 60 | + return os; |
| 61 | +} |
| 62 | + |
| 63 | +inline ostream& operator<<(ostream& os, unsigned int x) { |
| 64 | + printf("%u", x); |
| 65 | + return os; |
| 66 | +} |
| 67 | + |
| 68 | +inline ostream& operator<<(ostream& os, float x) { |
| 69 | + printf("%f", x); |
| 70 | + return os; |
| 71 | +} |
| 72 | + |
| 73 | +inline ostream& operator<<(ostream& os, double x) { |
| 74 | + printf("%f", x); |
| 75 | + return os; |
| 76 | +} |
| 77 | + |
| 78 | +constexpr char endl = '\n'; |
| 79 | +constexpr char ends = '\0'; |
| 80 | + |
| 81 | +constexpr char dec = '\0'; |
| 82 | +constexpr char oct = '\0'; |
| 83 | +constexpr char hex = '\0'; |
| 84 | +constexpr char basefield = '\0'; |
| 85 | +constexpr char left = '\0'; |
| 86 | +constexpr char right = '\0'; |
| 87 | +constexpr char internal = '\0'; |
| 88 | +constexpr char adjustfield = '\0'; |
| 89 | +constexpr char scientific = '\0'; |
| 90 | +constexpr char fixed = '\0'; |
| 91 | +constexpr char floatfield = '\0'; |
| 92 | +constexpr char boolalpha = '\0'; |
| 93 | +constexpr char showbase = '\0'; |
| 94 | +constexpr char showpoint = '\0'; |
| 95 | +constexpr char showpos = '\0'; |
| 96 | +constexpr char skipws = '\0'; |
| 97 | +constexpr char unitbuf = '\0'; |
| 98 | +constexpr char uppercase = '\0'; |
| 99 | + |
| 100 | +} // namespace fake |
| 101 | + |
| 102 | +#endif /* FAKE_IOSTREAM_H */ |
0 commit comments