Hacker News new | ask | show | jobs
by pyrtsa 5340 days ago
I think the lambdas are the more useful the more complicated the function is. Simple asynchronous tasks might be one such example. This one, however, still is a pretty common use case, so introducing a function object type for it wouldn't hurt readability. Something like:

    template <typename A, typename B>
    struct between_ {
        A a; B b;
        between_(A const & a, B const & b) : a(a), b(b) {}
        template <typename T>
        bool operator()(T const & t) const { return a < t && t < b; }
    };
    template <typename A, typename B>
    between_<A, B> between(A const & a, B const & b) {
        return between_<A, B>(a, b);
    }
    // ...
    auto i = find_if(begin(v), end(v), between(x, y));
Verbose? Admittedly. Except maybe for the point of use, i.e. the last line. Which, I think, helps a lot anyway.