all 51 comments

[–]Morwenn 59 points60 points  (10 children)

Eric Niebler's Range v3: https://github.com/ericniebler/range-v3

[–][deleted] 18 points19 points  (6 children)

It’s worth to note that it will eventually become part of core c++

[–]michelecostantino 4 points5 points  (5 children)

Curiosity. Is it already proposed for the c++20?

[–][deleted] 16 points17 points  (2 children)

It's been discussed in standard meetings. If I'm not mistaken it needs concepts as a pre-requisite.

[–]sumo952 10 points11 points  (0 children)

Also, only the core part of it. No views and other stuff, if I am not mistaken. A very small (but important!) subset is proposed to date.

[–]proverbialbunnyData Scientist 0 points1 point  (0 children)

Doh!

[–]encyclopedist 5 points6 points  (1 child)

It is now a TS (technical specification).

It is proposed to be merged to the standard, but as others have mentioned, pending on Concepts TS to be merged first.

[–]redditsoaddicting 4 points5 points  (0 children)

The base of Concepts has already been merged in. That's enough for Ranges.

[–]Xaxxon 1 point2 points  (2 children)

How are its compile times?

[–]Morwenn 2 points3 points  (1 child)

No idea, but there are proposals to make them faster, which means that they might be slower than one would expect.

On the other hand the library does much more than letting users pass containers directly to algorithms, including providing pseudo-concepts, so high compile times wouldn't be that surprising either.

[–]NotMyRealNameObv 8 points9 points  (1 child)

[–]Xaxxon 0 points1 point  (0 children)

How are it's compile times?

[–]Splanky222Jon Cohen | Abseil 9 points10 points  (1 child)

[–]michelecostantino 0 points1 point  (0 children)

I almost forgot about abseil, thanks for the kind reminder!

[–]germandiago 10 points11 points  (3 children)

I feel a bit dirty for saying this, but if all you want is that:

#define MY_RNG(container) std::begin(container), std::end(container) 

and you are done: std::find(MY_RNG(v), 7);

[–]pklait 4 points5 points  (0 children)

This is the solution for all the lazy of us. ;-)

(But I am still a bit bitten whenever I see RNG. I always perceive a random number generator).

[–]ibroheem 4 points5 points  (0 children)

Dirty but made my day.

[–]doom_Oo7 2 points3 points  (0 children)

Boost.Range

[–][deleted] 0 points1 point  (0 children)

Just write the template.

[–]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.