#ifndef NETGEN_CORE_RANGES_HPP #define NETGEN_CORE_RANGES_HPP #include namespace ngcore { template class AdapterRange { Iterator _begin,_end; public: AdapterRange(Iterator abegin, Iterator aend) : _begin(abegin), _end(aend) { ; } Iterator begin() const { return _begin; } Iterator end() const { return _end; } }; template class FilterAdapter { FUNC f; public: FilterAdapter(FUNC af) : f(af) { ; } FUNC GetFunction() const { return f; } }; template class FilterIterator { Iterator iter; Iterator end; FUNC f; public: FilterIterator(FUNC af, Iterator aiter, Iterator aend) : f(af), iter(aiter), end(aend) { while(iter!=end && !f(*iter)) ++iter; } inline FilterIterator& operator ++() { ++iter; while(iter!=end && !f(*iter)) ++iter; return *this; } inline bool operator !=(FilterIterator other) { return iter != other.iter; } inline bool operator ==(FilterIterator other) { return iter == other.iter; } inline decltype(auto) operator *() const { return *iter; } }; template FilterAdapter filter(FUNC f) { return {f}; } template auto operator |(Range&& range, FilterAdapter adapter) -> AdapterRange> { return {{adapter.GetFunction(),std::begin(range),std::end(range)}, {adapter.GetFunction(), std::end(range), std::end(range)}}; } template class TransformIterator { FUNC f; Iterator iter; public: TransformIterator(FUNC af, Iterator aiter) : f(af), iter(aiter) { ; } TransformIterator& operator++() { ++iter; } bool operator !=(TransformIterator other) { return iter != other.iter; } decltype(auto) operator *() const { return f(*iter); } }; template class TransformAdapter { FUNC f; public: TransformAdapter(FUNC af) : f(af) { ; } FUNC GetFunction() const { return f; } }; template TransformAdapter transform(FUNC f) { return {f}; } template auto operator |(Range&& range, TransformAdapter adapter) -> AdapterRange> { return {{adapter.GetFunction(), std::begin(range)}, {adapter.GetFunction(),std::end(range)}}; } } // namespace ngcore #endif // NETGEN_CORE_RANGES_HPP