When should the STL algorithms be used instead of

2020-05-21 08:47发布

I frequently use the STL containers but have never used the STL algorithms that are to be used with the STL containers.

One benefit of using the STL algorithms is that they provide a method for removing loops so that code logic complexity is reduced. There are other benefits that I won't list here.

I have never seen C++ code that uses the STL algorithms. From sample code within web page articles to open source projects, I haven't seen their use.

Are they used more frequently than it seems?

13条回答
劳资没心,怎么记你
2楼-- · 2020-05-21 09:14

The only time i don't use STL algorithms is when the cross-platform implementation differences affect the outcome of my program. This has only happened in one or two rare cases (on the Playstation 3). Although the interface of the STL is standardized across platforms, the implementation is not.

Also, in certain extremely high performance applications (think: video games, video game servers) we replaced a some STL structures with our own to eek out a bit more efficiency.

However, the vast majority of the time using STL is the way to go. And in my other (non video game) jobs, i used the STL exclusively.

查看更多
登录 后发表回答