verboseSection

Use verboseSection to display a message, flush it to the screen, and once the scope is over, display how much time the scope took to run. Message and timing info is only displayed when verbosity is enabled. Condition for "Is verbosity enabled?" can be customized with setVerboseSectionCond.

Usage:

bool verbose;

void foo()
{
	mixin(verboseSection!"Running foo");
	[...code here...]
}

void bar()
{
	{
		mixin(verboseSection!"Running bar stage 1");
		[...code here...]
	}

	{
		auto msg = "Running bar stage "~to!string(2);
		mixin(verboseSection!msg);
		[...code here...]
	}
}

void main()
{
	verbose = false;
	writeln("Verbose off");
	foo();
	bar();

	verbose = true;
	writeln("Verbose on");
	foo();
	bar();
}

Output:

Verbose off
Verbose on
Running foo...261ms
Running bar stage 1...7ms
Running bar stage 2...3528ms

You can change the conditional expression to something other than the default of "verbose" by using setVerboseSectionCond:

Usage:

struct Options
{
	bool verbose;
}
Options options;
mixin(setVerboseSectionCond!"options.verbose");

// Or:

int verbosityLevel;
mixin(setVerboseSectionCond!"verbosityLevel > 2");

Using setVerboseSectionCond only affects the current module. Use it again in each module desired.

  1. template setVerboseSectionCond(string cond = "verbose")
  2. template verboseSection(alias msg)
    template verboseSection (
    alias msg
    ) {}

Members

Manifest constants

verboseSection
enum verboseSection;
Undocumented in source.

Meta