|
Boost : |
From: nbecker_at_[hidden]
Date: 2001-05-17 12:46:40
I noticed we have a function_output_iterator, but I didn't see
function_input_iterator. Here it is.
Example usage:
A function expects to take an iterator as an input. You want to
provide a constant value. Use in conjuction with Constant.H:
#ifndef Constant_H
#define Constant_H
#include <functional>
template<typename out_t>
class Constant : public unary_function<out_t, out_t>{
const out_t val;
public:
Constant (out_t _val) :
val (_val) {}
template<typename T>
out_t operator() (T x) const {
return val;
}
out_t operator() () const {
return val;
}
};
#endif
#ifndef function_input_iterator_hpp
#define function_input_iterator_hpp
#include <iterator>
template <typename UnaryFunction>
class function_input_iterator {
typedef function_input_iterator self;
public:
typedef std::input_iterator_tag iterator_category;
typedef typename UnaryFunction::result_type value_type;
typedef void difference_type;
typedef void pointer;
typedef typename UnaryFunction::result_type& reference;
explicit function_input_iterator (const UnaryFunction& f = UnaryFunction()) :
m_f (f) {}
value_type operator*() { return m_f(); }
self& operator++() { return *this; }
self& operator++(int) { return *this; }
private:
UnaryFunction m_f;
};
template <typename UnaryFunction>
inline function_input_iterator<UnaryFunction>
make_function_input_iterator(const UnaryFunction& f = UnaryFunction()) {
return function_input_iterator<UnaryFunction>(f);
}
#endif
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk