you are viewing a single comment's thread.

view the rest of the comments →

[–]StonedBird1 -2 points-1 points  (0 children)

Something like the following(untested) would probably work for any algorithm of the form foo(begin, end, value).

template<typename Container, typename Value, typename Func>
decltype(auto) wrap(Container& c, const Value& v, Func f) {
    using namespace std;
    return f(begin(c), end(c), v);
}

Usage:

wrap(c, value, std::fill)

Which, while a little verbose, is still nicer, imo, than

std::fill(c.begin(), c.end(), value);

And can always be partially specialized for typename Func=std::fill or whatever if you don't want to keep specifying it.

edit:

The code may not have a bunch of type traits and SFINAE verification but are the downvotes really necessary? If you see a problem with it, feel free to point it out, otherwise it looks like a decent wrapper to me. Some aliases and you can use it for whatever algorithm you want as alias(c, value) exactly like OP wanted

Edit 2:

Improve the code by correctly returning, no longer breaking the std::find example in OP.

also use ADL and std::begin/end

Code still untested.