Conclusion
I have shown two implementations of the same algorithm, both taking advantage of the "new C++," the high-level language that C++ evolved into after the introduction of the standard template library. The use of C++ in the first implementation is reminiscent of string-manipulating languages such as Perl. The second implementation gives more control to the programmer. It makes the resource-management part of the program more obvious and, at the same time, separates it from the main part of the algorithm. It also gets rid of the little inefficiencies of the first implementation. Finally, it generalizes easily to situations where there is no obvious string representation for the items to be topologically sorted.