mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 15:04:00 +00:00
added docs for iterator_traits_generator
[SVN r9498]
This commit is contained in:
parent
26240403b0
commit
f353415136
@ -129,11 +129,11 @@
|
|||||||
<p><tt>iterator_adaptor</tt> is declared like this:
|
<p><tt>iterator_adaptor</tt> is declared like this:
|
||||||
<pre>
|
<pre>
|
||||||
template <class Base, class Policies,
|
template <class Base, class Policies,
|
||||||
class Value = typename std::iterator_traits<Base>::value_type,
|
class ValueOrNamedParams = typename std::iterator_traits<Base>::value_type,
|
||||||
class Reference = <i>...(see below)</i>,
|
class ReferenceOrNamedParams = <i>...(see below)</i>,
|
||||||
class Pointer = <i>...(see below)</i>,
|
class PointerOrNamedParams = <i>...(see below)</i>,
|
||||||
class Category = typename std::iterator_traits<Base>::iterator_category,
|
class CategoryOrNamedParams = typename std::iterator_traits<Base>::iterator_category,
|
||||||
class Distance = typename std::iterator_traits<Base>::difference_type>
|
class DistanceOrNamedParams = typename std::iterator_traits<Base>::difference_type>
|
||||||
struct iterator_adaptor;
|
struct iterator_adaptor;
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
@ -203,8 +203,79 @@ struct iterator_adaptor;
|
|||||||
<td>The <tt>difference_type</tt> for the resulting iterator.<br>
|
<td>The <tt>difference_type</tt> for the resulting iterator.<br>
|
||||||
<b>Default:</b>
|
<b>Default:</b>
|
||||||
<tt>std::iterator_traits<BaseType>::difference_type</tt>
|
<tt>std::iterator_traits<BaseType>::difference_type</tt>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td><tt>NamedParams</tt>
|
||||||
|
|
||||||
|
<td>A list of named template parameters generated using the
|
||||||
|
<a href="#iterator_traits_generator">
|
||||||
|
<tt>iterator_traits_generator</tt></a> class (see below).
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<h3><a name="named_template_parameters">Named Template Parameters</a></h3>
|
||||||
|
|
||||||
|
With seven template parameters, providing arguments for
|
||||||
|
<tt>iterator_adaptor</tt> in the correct order can be challenging.
|
||||||
|
Also, often times one would like to specify the sixth or seventh
|
||||||
|
template parameter, but use the defaults for the third through
|
||||||
|
fifth. As a solution to these problems we provide a mechanism for
|
||||||
|
naming the last five template parameters, and providing them in
|
||||||
|
any order through the <tt>iterator_traits_generator</tt> class.
|
||||||
|
|
||||||
|
<a name="iterator_traits_generator">
|
||||||
|
<blockquote>
|
||||||
|
<pre>
|
||||||
|
class iterator_traits_generator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template <class Value>
|
||||||
|
struct value_type : public <i>recursive magic</i> { };
|
||||||
|
|
||||||
|
template <class Reference>
|
||||||
|
struct reference : public <i>recursive magic</i> { };
|
||||||
|
|
||||||
|
template <class Pointer>
|
||||||
|
struct pointer : public <i>recursive magic</i> { };
|
||||||
|
|
||||||
|
template <class Distance>
|
||||||
|
struct difference_type : public <i>recursive magic</i> { };
|
||||||
|
|
||||||
|
template <class Category>
|
||||||
|
struct iterator_category : public <i>recursive magic</i> { };
|
||||||
|
};
|
||||||
|
</pre>
|
||||||
|
</blockquote>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
The <tt>iterator_traits_generator</tt> is used to create a list of
|
||||||
|
of template arguments. For example, suppose you want to set the
|
||||||
|
<tt>Reference</tt> and <tt>Category</tt> parameters, and use the
|
||||||
|
defaults for the rest. Then you can use the traits generator as
|
||||||
|
follows:
|
||||||
|
|
||||||
|
<blockquote>
|
||||||
|
<pre>
|
||||||
|
iterator_traits_generator::reference<foo>::category<std::input_iterator_tag>
|
||||||
|
</pre>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
|
This generated type can then be passed into the
|
||||||
|
<tt>iterator_adaptor</tt> class to replace any of the last five
|
||||||
|
parameters. If you use the traits generator in the <i>i</i>th
|
||||||
|
parameter position, then the parameters <i>i</i> through 7 will
|
||||||
|
use the types specified in the generator.
|
||||||
|
|
||||||
|
<blockquote>
|
||||||
|
<pre>
|
||||||
|
iterator_adaptor<foo_iterator, foo_policies,
|
||||||
|
iterator_traits_generator
|
||||||
|
::reference<foo>
|
||||||
|
::category<std::input_iterator_tag>
|
||||||
|
>
|
||||||
|
</pre>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
|
|
||||||
<h3><a name="policies">The Policies Class</a></h3>
|
<h3><a name="policies">The Policies Class</a></h3>
|
||||||
|
|
||||||
<p>The main task in using <tt>iterator_adaptor</tt> is creating an
|
<p>The main task in using <tt>iterator_adaptor</tt> is creating an
|
||||||
|
Loading…
x
Reference in New Issue
Block a user