6

It appears that zip_iterator, evaluates iterator_category to std::input_iterator_tag for the below code snippet.

But the implementation of std::fill in Xcode(i'm using Xcode10.1.0.app) has implementations specific to forward_iterator_tag and random_access_iterator_tag, but not input_iterator_tag. Thus the code results in the compilation error.

The same code compiles fine with gcc-6.3.0.

//zip_iterator.cpp
#include <boost/iterator/zip_iterator.hpp>
#include <iterator>
#include <iostream>

template <typename Iterator>
void FooImpl(Iterator first, Iterator last, std::input_iterator_tag ) { 
   std::cout<< "Input Iteartor Tag\n";
}

template <typename Iterator>
void Foo(Iterator first, Iterator last) {
    typedef typename std::iterator_traits<Iterator>::iterator_category category;
    FooImpl(first, last, category());
}

template<typename T>
void foo()
{
    boost::zip_iterator<boost::tuple<T*> > iter;
    Foo(iter,iter);
    std::fill(iter, iter, boost::make_tuple(T())); //Fails to compile
}

int main()
{
    foo<int>();
    return 0;
}

Is it a bug in boost zip_iterator that it generates "std::input_iterator_tag" as iterator_category,

OR

std::fill version of std::input_iterator_tag is missing in Xcode(clang) ?

kk07
  • 73
  • 4
  • 1
    It is not a clang bug. [`std::fill`](https://en.cppreference.com/w/cpp/algorithm/fill) is only required to support forward iterators. Either it is a boost bug or gcc is just being nice to you. – NathanOliver May 13 '19 at 12:20
  • I looked into GCC implementation of std::fill and found that it has a different implementation(from clang) based on concept checking. Basically, it checks if the type "ForwardIt" meet the requirements of LegacyForwardIterator. `template< class ForwardIt, class T > void fill( ForwardIt first, ForwardIt last, const T& value );` [link](https://en.cppreference.com/w/cpp/algorithm/fill) – kk07 May 14 '19 at 05:25

0 Answers0