BDE 4.14.0 Production release
|
Provide an output iterator type that discards output.
This component provides a mechanism, bdlb::NullOutputIterator
, that defines an output iterator with the following attributes:
This iterator type is typically used to call functions purely for their side-effects, discarding the normal output. It is also useful for testing whether a template function will compile when presented with a pure output iterator. This component also provides a template bdlb::NullOutputIterator::AssignmentProxy
, that is used as the return type of bdlb::NullOutputIterator::operator*
. The AssignmentProxy
provides an operator=
that does nothing, so that the result of the iterator's operator*
can be assigned to even if the value type of the bdlb::NullOutputIterator
does not provide a default constructor:
This section illustrates intended use of this component.
In the following example we use a bdlb::NullOutputIterator
to enable us to call a function to capture its return code, while ignoring the output provided through an iterator.
First, we define a function runningSum
that returns output both through an output iterator and through a return status code:
Now, we define a function average
that captures the total sum returned by runningSum
and uses a bdlb::NullOutputIterator
to facilitate calling the function, and ignoring the output it provides through its output iterator parameter:
Finally, we invoke function average
on user array and validate result.