log/nocost.cpp

/* This example shows how to create a log such that it will be completely
   optimized away unless you specify for it to generate code at compile time.
*/

#include <toast/log.hpp>

using namespace toast::log;

#ifdef DEBUG_OUTPUT
typedef logger<always_output> Log;
#else
typedef logger<never_output> Log;
#endif

void nocost_log_example()
{
  Log log;
  log.message("This message won't get logged unless DEBUG_OUTPUT is defined.");
  log.message("None of these lines should generate any code with");
  log.message("optimizations on either, unless DEBUG_OUTPUT is defined.");
}

SourceForge.net Logo