TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Why are there no STL algorithms that work on whole containers?

5 pointsby kevemanover 13 years ago

2 comments

makecheckover 13 years ago
I'm surprised he didn't give an even simpler reason, which is that algorithms were designed to work with pointers as well as objects.<p>You can't call begin() or end() on a pointer. And although you can figure out the end of a stack-allocated C array, you can't do it for a heap-based array. For example, with "x = new int[30]" and a call like "sort(x, ...)", you may know the size of "x" but the algorithm can't know. The solution is to make algorithms accept a form like "sort(x, x + 30, ...)".<p>Of course now, with things like std::array in the standard, there are fewer reasons to care about pointers than before.
kevemanover 13 years ago
Good point. I haven't used STL algorithms on raw pointers in quite a while, that I didn't think of that reason at all.