#ifndef _NTPM_AI_COUNTER_H
#define _NTPM_AI_COUNTER_H

#include <arithmetic_iterators/arithmetic_iterator.h>

namespace NTPMai {

template <class T>
class counter_iterator : public arithmetic_iterator
{
public:
    typedef counter_iterator<T> Self;
    typedef T value_type;
    typedef int difference_type;
    typedef T* pointer;
    typedef T& reference;
    typedef random_access_iterator_tag iterator_category;

    counter_iterator() : count(0), incr(1) {}
    counter_iterator(T _min, T _incr=1) :
                     count(_min), incr(_incr) {}
    value_type operator*() { return count; }
    Self &operator++() { count=count+incr; return *this; }
    bool operator==(const Self &i) const {
	return count==i.count;
    }
private:
    T count, incr;
};

// Note that this is NOT the same as counter(). max is never reached
// if you build a counter with this function.
template <class T>
Promise<counter_iterator<T> >
_make_counter_promise(T min, T max=-1, int incr=1)
{
    typedef counter_iterator<T> CIT;
    return NTPM::make_promise(CIT(min,incr), CIT(max,incr));
}


template <class T>
Promise<counter_iterator<T> >
counter(T min, T max=-1, int incr=1)
{
    return _make_counter_promise(min,max+1,incr);
}

}

#endif // _NTPM_AI_COUNTER_H
