[ create a new paste ] login | about

Link: http://codepad.org/avXRaQ9l    [ raw code | output | fork ]

C++, pasted on Jun 24:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

template <typename T>
class Iterator
{
public:
  typedef typename T::iterator IterType;
  Iterator(T& source) :
    begin(source.begin()),
    end(source.end()),
    current(begin)
  {
  }

  bool hasNext() const
  {
    return current != end;
  }

  IterType next()
  {
    return current++;
  }

private:
  IterType begin;
  IterType end;
  IterType current;
};

int main()
{
  vector<string> temp;
  temp.push_back("Some text 1");
  temp.push_back("Some text 2");

  Iterator<vector<string> > iter(temp);
  while(iter.hasNext())
  {
    cout << *iter.next() << endl;
  }


  string temp2 = "another test string";
  Iterator<string> iter2(temp2);
  while(iter2.hasNext())
  {
    cout << *iter2.next() << endl;
  }
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Some text 1
Some text 2
a
n
o
t
h
e
r
 
t
e
s
t
 
s
t
r
i
n
g


Create a new paste based on this one


Comments: