type-erased C++ output iterator
boost, c++, stl, type-erasure
Solution
`any_iterator` is not designed for use with output iterators, which is what `back_insert_iterator` is (or, for that matter, input iterators).
`back_insert_iterator` is defined to inherit from `iterator<output_iterator_tag, void, void, void, void>` i.e. its `value_type`, `reference_type`, `distance_type` and `pointer_type` are all `void`, but `any_iterator` expects to be able to indirect through its backing iterator to a non-void value. Perhaps it would be better named `any_value_iterator`; but then it is a `detail` class template.
Problem
How to erase type from output iterators as `std::insert_iterator` and `std::back_insert_iterator`? Is it possible to use boost `any_iterator` to do so? ``` #include <boost/range.hpp> #include <boost/range/detail/any_iterator.hpp> #include <vector> typedef boost::range_detail::any_iterator< int, boost::incrementable_traversal_tag, int &, std::ptrdiff_t > It; int main() { std::vector<int> v; It outIt( v.begin() ); // compiles It inserter( std::back_inserter(v) ); // does not compile return 0; } ```