title: avoid code duplication when writing iterator and const_iterator
body: <p>I'm trying to write a single iterator class that can cover both const_iterator and iterator classes to avoid code duplication.</p>
  
  <p>While reading some other questions, I came across <a href="https://stackoverflow.com/questions/2150192/how-to-avoid-code-duplication-implementing-const-and-non-const-iterators">this post</a> that asks the exact question I want.  The best response was <a href="http://www.drdobbs.com/the-standard-librarian-defining-iterato/184401331" rel="nofollow noreferrer">this article</a> that does a decent job explaining what I need to do in a paragraph, but refers to examples in books that I don't have.  My attempt to implement what is described is as follows:</p>
  
  <pre><code>      template&lt;bool c=0&gt; //determines if it is a const_iterator or not
        class iterator{
           typedef std::random_access_iterator_tag iterator_category;
           typedef T value_type;
           typedef T value_type;
           typedef std::ptrdiff_t difference_type;
           typedef (c ? (const T*) : (T*)) pointer; //problem line
           typedef (c ? (const T&amp;) : (T&amp;)) reference; //problem line
        public:
           operator iterator&lt;1&gt;(){ return iterator&lt;1&gt;(*this) }
           ...
        }
  </code></pre>
  
  <p>I can't figure out how to use the ternary operator to determine the typedef.  The specified lines get the compiler error "<em>expected ‘)’ before ‘?’ token</em>".  Am I interpreting the article wrong?</p>
  
  <p>Also, it says to write a converting constructor so that all my const functions can have non-const parameters converted.  Doesn't that mean that the program has to tediously construct new iterators for every parameter when using const_iterators?  It doesn't seem like a very optimal solution.</p>