source: doc/generic_types/evaluation/cpp-print.hpp @ 0d10090

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since 0d10090 was 0d10090, checked in by Aaron Moss <a3moss@…>, 4 years ago

Add printing code to benchmark

  • Property mode set to 100644
File size: 801 bytes
Line 
1#pragma once
2
3#include <iomanip>
4#include <iostream>
5#include <utility>
6
7template<typename T>
8void print(std::ostream& out, const T& x) { out << x; }
9
10template<>
11void print<bool>(std::ostream& out, const bool& x) { out << (x ? "true" : "false"); }
12
13template<>
14void print<char>(std::ostream& out, const char& x ) {
15        if ( 0x20 <= x && x <= 0x7E ) { out << "'" << x << "'"; }
16        else { out << "'\\" << std::hex << (unsigned int)x << std::setbase(0) << "'"; }
17}
18
19template<typename R, typename S>
20std::ostream& operator<< (std::ostream& out, const std::pair<R, S>& x) {
21        out << "[";
22        print(out, x.first);
23        out << ", ";
24        print(out, x.second);
25        return out << "]";
26}
27
28template<typename T, typename... Args>
29void print(std::ostream& out, const T& arg, const Args&... rest) {
30        out << arg;
31        print(out, rest...);
32}
Note: See TracBrowser for help on using the repository browser.