I am trying to implement an STL style RingBuffer. This means that I also execute an iterator for it, which should work both const and not const. This is only part of the iterator:
#include <iterator>
#include <type_traits>
template <typename T> class RingBuffer {
public:
class Iterator;
};
template <typename T, bool is_const=false>
class RingBuffer<T>::Iterator {
public:
typedef std::ptrdiff_t difference_type;
typedef T value_type;
typedef typename std::conditional<is_const, const value_type*, value_type*>::type pointer ;
typedef typename std::conditional<is_const, const value_type&, value_type&>::type reference ;
typedef std::random_access_iterator_tag iterator_category;
...
};
GCC 4.8.0 gives errors for every line where I try to access the iterator by saying something like
no type named 'type' in 'struct std::conditional<is_const, const int*, int*>'
Substitution intfor the type with which the instance was created RingBuffer<T>. I do not understand. is_consthas a default value. Why is this not working? And why doesn't GCC sign in falsein the error message, for example, does it replace intwith value_type?
The solution is probably obvious, but all the search engines in the world have not taken me anywhere. Patterns are still confusing me.