How to check if an iterator is an output_iterator in c++?
NickName:xmllmx Ask DateTime:2016-12-01T09:29:13

How to check if an iterator is an output_iterator in c++?

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

More about “How to check if an iterator is an output_iterator in c++?” related questions

How to check if an iterator is an output_iterator in c++?

template&lt;typename Iterator&gt; void put_value(Iterator pos, int n) { static_assert(IsOutputIterator&lt;Iterator&gt;); // // How to implement IsOutputIterator? // *pos = n; ...

Show Detail

Is vector<int>::const_iterator an output_iterator?

According to the C++ concepts: Any iterator other than input_iterator is an output_iterator. A vector&lt;int&gt;::const_iterator is a random_access_iterator, and of course that is an output_ite...

Show Detail

Specify output_iterator concept as function argument within a concept

I am trying to write some example of a concept that requires implementing a &quot;read&quot; method. This &quot;read&quot; method would take a number of bytes to read and an output iterator to writ...

Show Detail

Why does the output_iterator Concept not require the output_iterator_tag?

C++20 introduces proper Concepts for the different types of iterators in the standard library (input, output, forward, bidirectional, random access, ...). While the original named requirements for ...

Show Detail

template argument for ostream_iterator-each element is pair

I am trying to use ostream_iterator for writing a vector of pairs to a file.ostream_iterator requires a template argument to be applied at the time of declaration. The vector is defined as- vector...

Show Detail

Why does the Microsoft implementation of concept std::output_iterator<It,T> contain a cast of type T?

Ranges are complete in VS2019, see https://devblogs.microsoft.com/cppblog/c20-ranges-are-complete-in-visual-studio-2019-version-16-10/ Why does the output_iterator concept have a static cast in the

Show Detail

How can I implement various iterator categories in an elegant and efficient way?

I'm implementing STL containers, for example, vector. What confused me is the implementation of iterators. If I want to implement all iterator categories: input_iterator, output_iterator,

Show Detail

How to deduce iterator template type, or its template's nested type?

This questions begs a more preparation, so I provide some bits of code first and then the exact question Assuming I have the following type declared template&lt;typename T&gt; struct some_type { ...

Show Detail

How to search through a vecor with a second vector?

I currently have a vector in a textfile I am reading from. Currently I can search through this textfile fine and get the vector band from each artist (list of bands an artist has played for, reason...

Show Detail

Write vector values into multiple files at once in C++

I have the data in my vector. I am trying to write each vector value, say vector_name[0] into "examplezero.h" , vector_name[1] into "exampleone.h" and so on. The below code shows how I have created...

Show Detail