Output iterator's value_type

后端 未结 2 975
旧巷少年郎
旧巷少年郎 2020-12-31 00:15

The STL commonly defines an output iterator like so:

template
class insert_iterator
: public iterator

        
2条回答
  •  误落风尘
    2020-12-31 00:57

    The purpose of the value_type of an iterator is to define the type that is returned when that iterator is dereferenced. For output iterators, the only legitimate use of the dereference operator is when it is used in conjunction with the assignment operator--in the form of *output_iterator = value. The type that is returned when dereferencing an output iterator does not necessarily have any direct relationship with the types that can be stored via the output iterator. The only needed relationship is that there be some way of assigning the latter types to the former type.

    Moreover, the output iterator can store values of multiple types, and these types do not have to have any relationship with one another. Take for example the null_output_iterator described in Discarding the output of a function that needs an output iterator. That iterator can accept for storage any type of value.

提交回复
热议问题