Can a range-based algorithm be completely independent of (and yet optimized for any) container type?

I was wondering if boost :: range or range_v3 would coordinate free and member functions in a similar way so that std :: begin would match STL containers and C-like arrays (in terms of encoding typing, I mean)?

In particular, it would be convenient for me to call std :: sort on a list that automatically calls the best possible implementation given by std :: list :: sort .

After all, can member functions be considered interfaces for their common ones ( std :: list :: sort is never called in client code)?

+4
source share
1 answer

AFAIK, none of the libraries you mentioned are directly related to this. In C ++ 17, there is more than a suggestion to make f(x) and xf() equivalent, but as I mentioned above, I don't know if it will work with range-v3 algorithms.

I noticed a wonderful comment in range-v3 sort.hpp: // TODO Forward iterators, like EoP? . So, perhaps Nibler has ideas to maintain a more general look. ("EoP" are elements of Alex Stepanov's programming.)

One complication: the generic type uses iterators to change values, and list :: sort () reorders the links themselves. The difference is important if you care about what iterators specify after sorting, so you still need to choose which type you want. You could even argue that sort () should never call list :: sort (), given the different semantics.

+2
source

All Articles