Swap — The Simplest Function That Reveals Everything
Alex Stepanov — the creator of the STL — had a simple litmus test for any programming language: Look at how it implements swap. Three lines. The simplest function imaginable. But what C++ lets those three lines become is a beautiful piece of engineering. The test: a smooth gradient of implementations Stepanov’s point was not about swap itself. It was about generic programming. You define what swap means — exchange the values of two objects. Then you ask the language: can you give me a smooth gradient of implementations, from the most generic to the most specialized, without losing efficiency at any level? ...