Skip to content

Instantly share code, notes, and snippets.

@kvk1920
Last active March 25, 2018 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kvk1920/e4cab771137f3224927b250153f1752a to your computer and use it in GitHub Desktop.
Save kvk1920/e4cab771137f3224927b250153f1752a to your computer and use it in GitHub Desktop.
#include <iostream>
template <typename Function>
inline void VRep(size_t n, Function f) {
for (size_t i(0); i < n; ++i)
f();
}
class {
private:
std::ostream& ostream_ = std::cerr; //Put your ostream here
size_t shifts_ = 0;
bool on_ = true; //You can fast and simply turn off output
template <typename T>
void Print(const T& object) {
ostream_ << object;
}
template <typename T, typename ...Args>
void Print(const T& object, const Args& ...args) {
Print(object);
Print(args...);
}
public:
void AShift(size_t n = 1) { shifts_ += n; } //Add shift
void RShift(size_t n = 1) { shifts_ -= n; } //Remove shift
template <typename ...Args>
void operator()(const Args& ...args) {
if (on_) {
VRep(shifts_, [this](){ ostream_ << " "; });
Print(args...);
ostream_ << std::endl;
}
}
template <typename ...Args> // You can use it when you step into function
void In(const Args& ...args) {
AShift();
operator ()(args...);
}
template <typename ...Args> //You can use it before going out of function
void Out(const Args& ...args) {
RShift();
operator ()(args...);
}
} VDbg;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment