5.1.0
Freundlich's C++ toolkit
Loading...
Searching...
No Matches
fcppt.indent

Description

Indent functions.

Indent

This library provides a simple way to do indented output:

Consider a simple tree type:

struct tree
{
using container = std::vector<fcppt::recursive<tree>>;
int value;
container children;
};

An output function that indents each level of the tree can be written as follows:

void output(std::ostream &_stream, tree const &_tree, fcppt::indent::level const _indent)
{
_stream << fcppt::indent::print(_indent) << _tree.value << '\n';
for (fcppt::recursive<tree> const &inner : _tree.children)
{
output(_stream, inner.get(), fcppt::indent::extra(_indent));
}
}

The following code

tree const value{
.value = 1,
fcppt::make_recursive(tree{.value = 2, .children = tree::container{}}),
fcppt::make_recursive(tree{.value = 3, .children = tree::container{}}))};
output(std::cout, value, fcppt::indent::start());

will output

1
2
3

Classes

class  fcppt::indent::print
 Provides an output operator for indents. More...

Typedefs

using fcppt::indent::level = fcppt::strong_typedef< unsigned ,_>
 The integer type for indents.

Functions

fcppt::indent::level fcppt::indent::extra (fcppt::indent::level const _level)
 Increases the indent level.
fcppt::indent::level fcppt::indent::start ()
 The starting indent level.

Typedef Documentation

◆ level

The integer type for indents.

Function Documentation

◆ extra()

fcppt::indent::level fcppt::indent::extra ( fcppt::indent::level const _level)
inlinenodiscard

Increases the indent level.

◆ start()

fcppt::indent::level fcppt::indent::start ( )
inline

The starting indent level.