forked from boostorg/range
changed the separated function to become the new formatted adaptor.
This commit is contained in:
51
doc/reference/adaptors/formatted.qbk
Normal file
51
doc/reference/adaptors/formatted.qbk
Normal file
@ -0,0 +1,51 @@
|
||||
[/
|
||||
Copyright 2014 Neil Groves
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
/]
|
||||
[section:formatted formatted]
|
||||
|
||||
[table
|
||||
[[Syntax] [Code]]
|
||||
[[Pipe] [`rng | boost::adaptors::formatted()`]]
|
||||
[[Pipe] [`rng | boost::adaptors::formatted(sep)`]]
|
||||
[[Pipe] [`rng | boost::adaptors::formatted(sep, prefix)`]]
|
||||
[[Pipe] [`rng | boost::adaptors::formatted(sep, prefix, postfix)`]]
|
||||
[[Function] [`boost::adaptors::format(rng)`]]
|
||||
[[Function] [`boost::adaptors::format(rng, sep)`]]
|
||||
[[Function] [`boost::adaptors::format(rng, sep, prefix)`]]
|
||||
[[Function] [`boost::adaptors::format(rng, sep, prefix, postfix)`]]
|
||||
]
|
||||
|
||||
This adaptor produces a range that can be output streamed to a
|
||||
`std::basic_ostream` to produce the output string formatted output. With the
|
||||
default paramters given numbers 1 to 5 inclusively in a range the output when
|
||||
streamed would be "{0,1,2,3,4,5}". The prefix, separator and postfix may be
|
||||
passed as parameters.
|
||||
|
||||
The general format of the output is thus:
|
||||
<prefix><element_1><sep><element_2><sep>...<element_n><postfix>
|
||||
|
||||
* [*Precondition:]
|
||||
* `0 <= n`.
|
||||
* `sep` has a type that is CopyConstructible and able to be streamed to `std::basic_ostream<Char,Traits>`
|
||||
* `prefix` has a type that is CopyConstructible and able to be streamed to `std::basic_ostream<Char,Traits>`
|
||||
* `postfix` has a type that is CopyConstructible and able to be streamed to `std::basic_ostream<Char,Traits>`
|
||||
* [*Returns:] `boost::range::formatted_range<Iter, Sep, Prefix, Postfix>` where
|
||||
`Iter` is `typename boost::range_iterator<Rng>::type`, `Sep` is the separator
|
||||
type, `Prefix` is the prefix type and `Postfix` is the postfix type.
|
||||
* [*Range Category:] __single_pass_range__
|
||||
* [*Returned Range Category:] The range category of `rng`.
|
||||
|
||||
[section:formatted_example formatted example]
|
||||
[import ../../../test/adaptor_test/formatted_example.cpp]
|
||||
[separated_example]
|
||||
[endsect]
|
||||
|
||||
This would produce the output:
|
||||
``
|
||||
{1,2,3,4,5}
|
||||
``
|
||||
[endsect]
|
||||
|
||||
|
@ -10,7 +10,6 @@ Having an abstraction that encapsulates a pair of iterators is very useful. The
|
||||
* Class `iterator_range`
|
||||
* Class `sub_range`
|
||||
* Function `combine`
|
||||
* Function `separated`
|
||||
* Function `join`
|
||||
|
||||
The `iterator_range` class is templated on an __forward_traversal_iterator__ and should be used whenever fairly general code is needed. The `sub_range` class is templated on an __forward_range__ and it is less general, but a bit easier to use since its template argument is easier to specify. The biggest difference is, however, that a `sub_range` can propagate constness because it knows what a corresponding `const_iterator` is.
|
||||
@ -405,55 +404,6 @@ For the mutable version:
|
||||
The expression `join(irange(0,5), irange(5,10))` would evaluate to a range representing an integer range `[0,10)`
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:separated Function separated]
|
||||
|
||||
The separated function allows output streaming a range while writing a separator
|
||||
between each element.
|
||||
|
||||
[h4 Synopsis]
|
||||
|
||||
``
|
||||
template<typename Iterator, typename Separator>
|
||||
class output_stream_writer
|
||||
{
|
||||
// ... unspecified
|
||||
};
|
||||
|
||||
template<typename Char, typename Traits>
|
||||
std::basic_ostream<Char,Traits>& operator<<(
|
||||
std::basic_ostream<Char,Traits>& out,
|
||||
const output_stream_writer<Iterator, Separator>& writer);
|
||||
|
||||
template<typename Range, typename Separator>
|
||||
boost::range::output_stream_writer<
|
||||
typename boost::range_iterator<const Range>::type,
|
||||
Separator
|
||||
> separated(const Range& rng, Separator separator);
|
||||
``
|
||||
|
||||
[h4 Example]
|
||||
|
||||
``
|
||||
#include <boost/range/separated.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
int main(int, const char*[])
|
||||
{
|
||||
std::vector<int> v;
|
||||
for (int i = 0; i < 5; ++i)
|
||||
v.push_back(v);
|
||||
|
||||
std::cout << '{' << boost::range::separated(v, ',') << '}' << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
``
|
||||
|
||||
Produces the output: `{0,1,2,3,4}`
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
Reference in New Issue
Block a user