2 ms·
According to https://en.cppreference.com/w/cpp/algorithm/stable_sort https://en.cppreference.com/w/cpp/algorithm/stable_sort: > This function attempts to alloc
by MauranKilom 6y ago
According to https://en.cppreference.com/w/cpp/algorithm/stable_sort https://en.cppreference.com/w/cpp/algorithm/stable_sort:
> This function attempts to allocate a temporary buffer equal in size to the sequence to be sorted. If the allocation fails, the less efficient algorithm is chosen.
Or is this not what you consider a "functional construct"?
- elbows 6y agoIt's more of an issue with things like std::transform or std::copy_if. Ergonomically, it's nice if these kinds of functions either allocate and return a new container, or return an iterator that yields the elements of the result. But the C++ versions of these take the result location as an argument. It makes chaining them together a hassle because you have to create all the intermediate containers explicitly. I think there are good reasons for the STL to work this way, but it can make programming in a functional style pretty inconvenient compared to a lot of other languages.
- leni536 6y agoRanges will help with some of the composability issues of standard library algorithms. [1] https://en.cppreference.com/w/cpp/ranges https://en.cppreference.com/w/cpp/ranges
- entha_saava 6y agoI know some basic C++ and STL. Is there anything like streams in C++. I mean things would be as easy as vec.stream().map(lambda).fold(T::operator+), so it wouldn't require any more allocations than those done by copy constructors.
- MauranKilom 6y agoThe upcoming ranges library will provide exactly this! It uses | for composing operations. See e.g. here: https://github.com/ericniebler/range-v3/tree/master/example https://github.com/ericniebler/range-v3/tree/master/example