Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to know whether std::iterator_traits<T>::value_type is defined
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/11898657/enable-if-iterator-as-a-default-template-parameter">enable_if iterator as a default template parameter?</a> </p> </blockquote> <p>I'm looking for solution to know at compile-time whether <code>std::iterator_traits&lt;T&gt;::value_type</code> is valid and defined. The problem with this is that std library forwards the declaration of value_type to the derived type in T:</p> <pre><code>typedef T::value_type value_type; </code></pre> <p>I need to know whether T::value_type is valid type or not in compile time to avoid errors related to value_type not existing. </p> <p>Please consider these examples:</p> <pre><code>std::iterator_traits&lt;int *&gt;::value_type; // OK - should return that value_type exists as it's defined in specialization of std::iterator_traits std::iterator_traits&lt;const int *&gt;::value_type; // OK - should return that value_type exists as it's defined in specialization of std::iterator_traits std::iterator_traits&lt;std::vector&lt;int&gt;::const_iterator&gt; &gt;::value_type; // OK - the value_type exists defined within std::vector&lt;int&gt;::const_iterator std::iterator_traits&lt;int&gt;::value_type; // ERROR - the value_type is not defined within int class - this is what I'm trying to avoid to resolve the value_type of. </code></pre> <p>I need the solution to be fully compliant with C++ standard and std library standard and compiler independent.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload