#ifndef SELECT_H_ #define SELECT_H_ #include template class Select { public: typedef typename boost::result_of::type ElementType; typedef typename Source::MarkerType MarkerType; public: Select(Source source, Fn fn) : source(source), fn(fn) { } bool step() { if(!this->source.step() ) return false; this->current = this->fn(*this->source.get() ); return true; } ElementType* get() { return ¤t; } MarkerType mark() const { return this->source.mark(); } void restore(MarkerType mark) { this->source.restore(mark); this->current = this->fn(*this->source.get() ); } private: Source source; Fn fn; ElementType current; }; namespace db { template struct SelectOp { Pred pred; template friend Select operator|(Source source, const SelectOp& op) { return Select(source, op.pred); } }; template inline SelectOp select(Pred pred) { SelectOp result = {pred}; return result; } } #endif