Created
October 2, 2014 10:04
-
-
Save vguerra/53b03d589ecdbd93d31f to your computer and use it in GitHub Desktop.
Eliminating branches with templates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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