Skip to content

Instantly share code, notes, and snippets.

@metaflow
Last active November 15, 2017 19:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metaflow/87d7df206e1e0a9fa9eb8a5dc4ac6bea to your computer and use it in GitHub Desktop.
Save metaflow/87d7df206e1e0a9fa9eb8a5dc4ac6bea to your computer and use it in GitHub Desktop.
#if defined(LOCAL)
#include "logging.h"
#define L(x...) (debug(x, #x))
#else
#define L(x, ...) (x)
#endif
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if (L(a + b, a, b) == 42) {
cout << "well done!" << endl;
}
}
#ifndef H_LOGGING
#define H_LOGGING
// https://louisdx.github.io/cxx-prettyprint/
#include "prettyprint.hpp"
template<typename T>
void _out_to_stream(std::ostream& ss, T&& arg) {
ss << std::forward<T>(arg);
}
template<typename T, typename... O>
void _out_to_stream(std::ostream& ss, T&& arg, O&&... args) {
ss << std::forward<T>(arg) << ' ';
_out_to_stream(ss, std::forward<O>(args)...);
}
template<typename T, typename... O>
decltype(auto) debug(T&& arg, O&&... args) {
std::stringstream ss;
_out_to_stream(ss, std::forward<T>(arg), std::forward<O>(args)...);
std::cerr << ss.str() << std::endl;
return std::forward<T>(arg);
}
#endif // H_LOGGING
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment