Why doesn't my custom iterator work with the STL copy?

前端 未结 4 1669
既然无缘
既然无缘 2021-01-02 05:02

I wrote an OutputIterator for an answer to another question. Here it is:

#include 

using namespace std;

template< typename T, typename U &g         


        
4条回答
  •  不知归路
    2021-01-02 05:31

    Your iterator doesn't meet the requirement for an 'assignable' type which is a requirement for an output iterator because it contains a reference and assignable types need to ensure that after t = u that t is equivalent to u.

    You can provide a suitable specialization for iterator_traits for your iterator either by deriving from a specialization of std::iterator or by providing one explicitly.

    namespace std
    {
        template<> struct iterator_traits
        {
            typedef std::output_iterator_tag iterator_category;
            typedef void value_type;
            typedef void difference_type;
        };
    }
    

提交回复
热议问题