mercredi 7 juin 2017

Why the OuputIterator concept doesn't have a value_type associated?

I am programming a library where I need to make an iterator interface and I want to make it as general as possible.

template<class OutputIterator>
void receive(OutputIterator oit){
    auto val = get_function< std::iterator_traits<OutputIterator>::value_type > (); // legacy function
    oit = val;
}

To my surprise for most output iterators value_type is void. (void renders the code invalid because a void variable cannot be declared).

Here two examples:

http://ift.tt/28JABG3

http://ift.tt/1Lgzoo4

However in both cases there is an obvious value type associated, I could hack into each and "see" that there is a value type. For example back_insert_iterator::container_type::value_type (but not accessible from iterator_traits).

Why is the standard trying to hide the value_type of the output iterators?

Maybe the correct terms is not value_type but there is obviously some type associated. Is this an overlook? Am I using the output iterator incorrectly?

Aucun commentaire:

Enregistrer un commentaire