Skip to content

Instantly share code, notes, and snippets.

@vguerra
Created October 2, 2014 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vguerra/53b03d589ecdbd93d31f to your computer and use it in GitHub Desktop.
Save vguerra/53b03d589ecdbd93d31f to your computer and use it in GitHub Desktop.
Eliminating branches with templates
#include <iostream>
#include <string>
template <bool B>
void Log(std::ostream& out, const std::string& str) {
if (B) {
out << str << "\n";
}
}
int main() {
Log<true>(std::cout, "This is going to be printed");
Log<false>(std::cout, "This should not");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment