Listing B


// prefix each element by its index

class PrefixByIndex

{

public:

  PrefixByIndex()

    : m_idxCurrent( 0)

  {}
 

  template< class StreamType, class Type>

  void operator()( StreamType & streamOut, const Type & value)

  {

   streamOut << "[" << m_idxCurrent << "] " << value;

    ++ m_idxCurrent;

  }

private:

  int m_idxCurrent;

};