Skip to content

Instantly share code, notes, and snippets.

@carlos-urena
Created November 1, 2019 10:27
Show Gist options
  • Save carlos-urena/6290b4fa0a5c50efd7bd2c4f0b5c54d8 to your computer and use it in GitHub Desktop.
Save carlos-urena/6290b4fa0a5c50efd7bd2c4f0b5c54d8 to your computer and use it in GitHub Desktop.
C++ definitions for logging lines, by using a variadic macro (Log) and variadic templates (Log2 and Log3)
void Log3()
{
cout << endl ;
}
template<typename T, typename ...Tipos>
void Log3( const T & first, const Tipos & ...parametros )
{
using namespace std ;
cout << first << " ";
Log3(parametros...);
}
template<typename ...Tipos>
void Log2( const std::string & file, const std::string & funct, const int line_num,
const Tipos & ...parametros )
{
using namespace std ;
cout << "file: " << file << ", function: " << funct << ", line: " << line_num << " --> " ;
Log3<Tipos...>(parametros...);
}
#define Log( ... ) Log2( __FILE__, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__ )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment