#ifndef _NTPM_AI_CONST_H
#define _NTPM_AI_CONST_H

#include <arithmetic_iterators/arithmetic_iterator.h>

namespace NTPMai {

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

    constant_iterator() : count(0) {}
    constant_iterator(T _val, int _count=-1) : val(_val), count(_count) {}
    value_type operator*() { return val; }
    Self &operator++() { ++count; return *this; }
    Self &operator--() { ++count; return *this; }
    bool operator==(const Self &i) const {
	return i.count==-1?true: count==i.count;
    }
private:
    T val;
    int count;
};


template <class T>
Promise<constant_iterator<T> >
make_constant_promise(T v, int count=-1)
{
    typedef constant_iterator<T> CIT;
    return NTPM::make_promise(CIT(v,0), CIT(v,count));
}

template <class T>
Promise<constant_iterator<T> >
constant(T v, int count=-1)
{
    return make_constant_promise(v,count);
}

}

#endif // _NTPM_AI_CONST_H
