• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[/
2    Copyright 2010 Neil Groves
3    Distributed under the Boost Software License, Version 1.0.
4    (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5/]
6[section:type_erased type_erased]
7
8[table
9    [[Syntax] [Code]]
10    [[Pipe] [`rng | boost::adaptors::type_erased<Value, Traversal, Reference, Difference, Buffer>()`]]
11    [[Function] [`boost::adaptors::type_erase(rng, boost::adaptors::type_erased<Value, Traversal, Reference, Difference, Buffer>)`]]
12]
13
14Please note that it is frequently unnecessary to use the `type_erased` adaptor. It is often better to use the implicit conversion to `any_range`.
15
16Let `Rng` be the type of `rng`.
17
18* [*Template parameters:]
19    * `Value` is the `value_type` for the `any_range`. If this is set to boost::use_default, `Value` will be calculated from the
20        range type when the adaptor is applied.
21    * `Traversal` is the tag used to identify the traversal of the resultant range. Frequently it is desirable to set a traversal category lower than the source container or range to maximize the number of ranges that can convert to the `any_range`. If this is left as boost::use_default then `Traversal` will be `typename boost::iterator_traversal<boost::range_iterator<Rng>::type>::type`
22    * `Reference` is the `reference` for the `any_range`. `boost::use_default` will equate to `typename range_reference<Rng>::type`.
23    * `Difference` is the `difference_type` for the any_range. `boost::use_default` will equate to `typename boost::range_difference<Rng>::type`
24    * `Buffer` is the storage used to allocate the underlying iterator wrappers. This can typically be ignored, but is available as a template parameter for customization. Buffer must be a model of the `AnyIteratorBufferConcept`.
25* [*Precondition:]  `Traversal` is one of `{ boost::use_default, boost::single_pass_traversal_tag, boost::forward_traversal_tag, boost::bidirectional_traversal_tag, boost::random_access_traversal_tag }`
26* [*Returns:] The returned value is the same as `typename any_range_type_generator< Rng, Value, Traversal, Reference, Difference, Buffer >` that represents `rng` in a type-erased manner.
27* [*Range Category:] __single_pass_range__
28* [*Returned Range Category:] if `Traversal` was specified as `boost::use_default` then `typename boost::iterator_traversal<boost::range_iterator<Rng>::type>::type`, otherwise `Traversal`.
29
30[heading AnyIteratorBufferConcept]
31``
32class AnyIteratorBufferConcept
33{
34public:
35    AnyIteratorBufferConcept();
36    ~AnyIteratorBufferConcept();
37
38    // bytes is the requested size to allocate. This function
39    // must return a pointer to an adequate area of memory.
40    // throws: bad_alloc
41    //
42    // The buffer will only ever have zero or one
43    // outstanding memory allocations.
44    void* allocate(std::size_t bytes);
45
46    // deallocate this buffer
47    void deallocate();
48};
49``
50
51[section:type_erased_example type-erased example]
52[import ../../../test/adaptor_test/type_erased_example.cpp]
53[type_erased_example]
54[endsect]
55
56This would produce the output:
57``
581,2,3,4,5,
596,7,8,9,10,
6011,12,13,14,15,
6111,12,13,14,15,
62``
63[endsect]
64
65
66