template<typename Iterator>
void put_value(Iterator pos, int n)
{
static_assert(IsOutputIterator<Iterator>);
//
// How to implement IsOutputIterator?
//
*pos = n;
}
std::iterator_traits<Iterator>::iterator_category
doesn't help. For example: vector<int>::iterator
is obvious an output_iterator
, but std::iterator_traits<vector<int>::iterator>::iterator_category
will returns random_access_iterator
, which might not be an output_iterator
, say a const_iterator
.
Is there any viable way to check if an iterator is an output_iterator in c++?
Copyright Notice:Content Author:「xmllmx」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40901170/how-to-check-if-an-iterator-is-an-output-iterator-in-c