Skip to content

debug.h ~ debug ~ init

Baptiste Thémine edited this page Feb 11, 2020 · 5 revisions
std::ios& init(std::ios &ios) noexcept;

Description

Initializes iostream properties to their default value.

debug::init also permits to set debug flag according to the macro DEBUG which can be defined before include or as compiler command line argument -DDEBUG=value. If no value is set, the macro DEBUG expands to value 1.

The following properties are initialized :

Name Value
debug::flag if macro DEBUG is defined then debug::level<DEBUG> else debug::off
ios.clear std::goodbit
ios.exceptions disabled like debug::noexcept_on_fail
ios.fill whitespace character ' '
ios.flags std::dec | std::skipws
ios.precision 6

Parameters

  • ios --> reference to an iostream object.

Return value

Returns a reference to ios passed in argument.

Exceptions

Never throws exception.

Examples

If a program starts as below :

#include <iostream>
#include <JLC/debug.h>

int main(){
    std::cout << debug::init;
    std::cin >> debug::init;
}

Then we can control our debug flag through compiler command line arguments :

//diagnostics and debug flag disabled
g++ -c test.cpp

//diagnostics and debug flag enabled
clang++ -c test.cpp -DDEBUG

//diagnostics enabled and debug flag disabled
g++ -c test.cpp -DDEBUG=0

//diagnostics enabled and debug flag set to level3
clang++ -c test.cpp -DDEBUG=3

See also

Clone this wiki locally