...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
The maxwidth[]
directive allows to limit (truncate) the overall length of the output
generated by the embedded generator.
// forwards to <boost/spirit/home/karma/directive/maxwidth.hpp> #include <boost/spirit/include/karma_maxwidth.hpp>
Also, see Include Structure.
Name |
---|
|
Notation
a
A generator object
A
Attribute type of the generator a
num
Numeric literal, any unsigned integer value, or a Lazy Argument that evaluates to an unsigned integer value
Semantics of an expression is defined only where it differs from, or
is not defined in UnaryGenerator
.
Expression |
Semantics |
---|---|
|
Limit the overall length of the emitted output of the embedded
generator (including characters generated by automatic delimiting)
to the number of characters as defined by the preprocessor
constant |
|
Limit the overall length of the emitted output of the embedded
generator (including characters generated by automatic delimiting)
to the number of characters as defined by |
Note | |
---|---|
The
If the output needs to always be equal to a specified column width,
use one of the alignment directives maxwidth(8)[left_align(8)["1234"]]
which will output: |
See Compound Attribute Notation.
Expression |
Attribute |
---|---|
|
a: A --> maxwidth[a]: A a: Unused --> maxwidth[a]: Unused
|
|
a: A --> maxwidth(num)[a]: A a: Unused --> maxwidth(num)[a]: Unused
|
The overall complexity of the generator directive
maxwidth[]
is defined by the complexity of its embedded generator. The complexity of the directive itself is O(N), whereN
is the number of characters generated by the maxwidth directive.
Note | |
---|---|
The test harness for the example(s) below is presented in the Basics Examples section. |
Some includes:
#include <boost/spirit/include/karma.hpp> #include <iostream> #include <string>
Some using declarations:
using boost::spirit::karma::double_; using boost::spirit::karma::maxwidth; using boost::spirit::karma::left_align; using boost::spirit::karma::right_align;
Basic usage of maxwidth
generator directive:
test_generator("01234", maxwidth(5)["0123456789"]); test_generator(" 012", maxwidth(5)[right_align(12)["0123456789"]]); test_generator("0123 ", maxwidth(8)[left_align(8)["0123"]]);