Listing 1: An Slist_iterator class, complete except for the equality operator

template <bool flag, class IsTrue, class IsFalse>
struct choose;

template <class IsTrue, class IsFalse>
struct choose<true, IsTrue, IsFalse> {
   typedef IsTrue type;
};

template <class IsTrue, class IsFalse>
struct choose<false, IsTrue, IsFalse> {
   typedef IsFalse type;
};

template <class T, bool isconst = false> 
struct slist_iterator {
   typedef std::forward_iterator_tag iterator_category;
   typedef T value_type;
   typedef std::ptrdiff_t difference_type;
   typedef typename choose<isconst, const T&, T&>::type
           reference;
   typedef typename choose<isconst, const T*, T*>::type
           pointer;

   typedef typename choose<isconst, const slist_node<T>*,    
                           slist_node<T>*>::type
           nodeptr;

  slist_iterator(nodeptr x = 0) : p(x) { }
  slist_iterator(const slist_iterator<T, false>& i) 
     : p(i.p) { }
  reference operator*() const { return p->val; }
  pointer operator->() const { return &(p->val); }
  slist_iterator& operator++() { 
     p = p->next; 
     return *this; 
  }
  slist_iterator operator++(int) {
     slist_iterator tmp(*this);
     ++*this;
     return tmp;
  }

   nodeptr p;
};

— End of Listing —