#ifndef RTORRENT_FUNCTIONAL_H #define RTORRENT_FUNCTIONAL_H #include namespace func { template inline void for_each(Iterator first, Iterator last, Ftor ftor) { Iterator tmp; while (first != last) { tmp = first++; ftor(*tmp); } } template struct _accumulate { _accumulate(Type& t, Ftor f) : m_t(t), m_f(f) {} template void operator () (Arg& a) { m_t += m_f(a); } Type& m_t; Ftor m_f; }; template inline _accumulate accumulate(Type& t, Ftor f) { return _accumulate(t, f); } template struct _equal { _equal(Type t, Ftor f) : m_t(t), m_f(f) {} template bool operator () (Arg& a) { return m_t == m_f(a); } Type m_t; Ftor m_f; }; template inline _equal equal(Type t, Ftor f) { return _equal(t, f); } template struct _on : public std::unary_function { _on(Dest d, Src s) : m_dest(d), m_src(s) {} typename Dest::result_type operator () (typename Src::argument_type arg) { return m_dest(m_src(arg)); } Dest m_dest; Src m_src; }; template inline _on on(Dest d, Src s) { return _on(d, s); } struct _call_delete : public std::unary_function { template void operator () (Type* t) { delete t; } }; inline _call_delete call_delete() { return _call_delete(); } } #endif