Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<class T> class Iterable
- {
- T start,stop;
- public:
- explicit Iterable(T s,T e) {start=s; stop=e;}
- public:
- virtual void next(T& i);
- public:
- class iterator: public std::iterator<
- std::input_iterator_tag, // iterator_category
- T, // value_type
- long, // difference_type
- const T*, // pointer
- T // reference
- >{
- T current;
- Iterable<T>& obj;
- public:
- explicit iterator(T t,Iterable<T>& o) : obj(o) {current=t;}
- iterator& operator++() {obj.next(current); return *this;}
- iterator operator++(int) {iterator retval = *this; ++(*this); return retval;}
- bool operator==(iterator other) const {return current == other.current;}
- bool operator!=(iterator other) const {return !(*this == other);}
- T operator*() const {return current;}
- };
- iterator begin() {return iterator(start,*this);}
- iterator end() {return iterator(stop,*this);}
- };
- class Range : public Iterable<long>
- {
- long START,STOP;
- public:
- void next(long& cur) override
- {
- if(START>=STOP)
- cur++;
- else
- cur--;
- }
- public:
- Range(long st,long en) : Iterable(st,en) {START=st; STOP=en;}
- };
- undefined reference to `flex::Iterable<long>::next(long&)'
- collect2: error: ld returned 1 exit status
- (After includes)
- int main()
- {
- Range range=Range(15,10);
- for(auto r : range)
- cout << r << "n";
- }
Add Comment
Please, Sign In to add comment