Sunday, September 27, 2015

Use of the showPlus format flag

Pantheios 1.0.1 beta 215 introduces the showPlus format flag, which causes leading pluses to be applied to integers (just as leading minuses will appear for negative numbers).

It is used as follows:

#include <pantheios/pan.hpp>
#include <pantheios/inserters/i.hpp>

int main()
{
  pan::log_INFORMATIONAL("log -10:");
  pan::log_INFORMATIONAL("without showPlus: '", pan::i(-10), "'");
  pan::log_INFORMATIONAL("with    showPlus: '", pan::i(-10, 0, pan::fmt::showPlus), "'");
  pan::log_INFORMATIONAL("----------\n");

  pan::log_INFORMATIONAL("log +10:");
  pan::log_INFORMATIONAL("without showPlus: '", pan::i(+10), "'");
  pan::log_INFORMATIONAL("with    showPlus: '", pan::i(+10, 0, pan::fmt::showPlus), "'");
  pan::log_INFORMATIONAL("----------\n");


  pan::log_INFORMATIONAL("log -10 into 10-width:");
  pan::log_INFORMATIONAL("without showPlus: '", pan::i(-10, 10, 0), "'");
  pan::log_INFORMATIONAL("with    showPlus: '", pan::i(-10, 10, pan::fmt::showPlus), "'");
  pan::log_INFORMATIONAL("----------\n");

  pan::log_INFORMATIONAL("log +10 into 10-width:");
  pan::log_INFORMATIONAL("without showPlus: '", pan::i(+10, 10, 0), "'");
  pan::log_INFORMATIONAL("with    showPlus: '", pan::i(+10, 10, pan::fmt::showPlus), "'");
  pan::log_INFORMATIONAL("----------\n");


  pan::log_INFORMATIONAL("log -10 into 10-width left-justified:");
  pan::log_INFORMATIONAL("without showPlus: '", pan::i(-10, -10, 0), "'");
  pan::log_INFORMATIONAL("with    showPlus: '", pan::i(-10, -10, pan::fmt::showPlus), "'");
  pan::log_INFORMATIONAL("----------\n");

  pan::log_INFORMATIONAL("log +10 into 10-width left-justified:");
  pan::log_INFORMATIONAL("without showPlus: '", pan::i(+10, -10, 0), "'");
  pan::log_INFORMATIONAL("with    showPlus: '", pan::i(+10, -10, pan::fmt::showPlus), "'");
  pan::log_INFORMATIONAL("----------\n");


  return 0;
}

PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.scratch.showPlus.integer");

which gives the output:

[test.scratch.showPlus.integer...]: log -10:
[test.scratch.showPlus.integer...]: without showPlus: '-10'
[test.scratch.showPlus.integer...]: with    showPlus: '-10'
[test.scratch.showPlus.integer...]: ----------

[test.scratch.showPlus.integer...]: log +10:
[test.scratch.showPlus.integer...]: without showPlus: '10'
[test.scratch.showPlus.integer...]: with    showPlus: '+10'
[test.scratch.showPlus.integer...]: ----------

[test.scratch.showPlus.integer...]: log -10 into 10-width:
[test.scratch.showPlus.integer...]: without showPlus: '       -10'
[test.scratch.showPlus.integer...]: with    showPlus: '       -10'
[test.scratch.showPlus.integer...]: ----------

[test.scratch.showPlus.integer...]: log +10 into 10-width:
[test.scratch.showPlus.integer...]: without showPlus: '        10'
[test.scratch.showPlus.integer...]: with    showPlus: '       +10'
[test.scratch.showPlus.integer...]: ----------

[test.scratch.showPlus.integer...]: log -10 into 10-width left-justified:
[test.scratch.showPlus.integer...]: without showPlus: '-10       '
[test.scratch.showPlus.integer...]: with    showPlus: '-10       '
[test.scratch.showPlus.integer...]: ----------

[test.scratch.showPlus.integer...]: log +10 into 10-width left-justified:
[test.scratch.showPlus.integer...]: without showPlus: '10        '
[test.scratch.showPlus.integer...]: with    showPlus: '+10       '
[test.scratch.showPlus.integer...]: ----------


3 comments:

  1. Holy S* dude, you're alive. I don't suppose we can continue to hope for 'Breaking up the Monolith', can we?

    ReplyDelete
  2. I'd like to think so, but may not be for another year.

    I'm intending to start a shortish digestible book very soon.

    ReplyDelete