print.hpp 799 B

123456789101112131415161718192021222324252627
  1. /* The following code example is taken from the book
  2. * "The C++ Standard Library - A Tutorial and Reference"
  3. * by Nicolai M. Josuttis, Addison-Wesley, 1999
  4. *
  5. * (C) Copyright Nicolai M. Josuttis 1999.
  6. * Distributed under the Boost Software License, Version 1.0. (See
  7. * accompanying file LICENSE_1_0.txt or copy at
  8. * http://www.boost.org/LICENSE_1_0.txt)
  9. */
  10. #include <iostream>
  11. /* print_elements()
  12. * - prints optional C-string optcstr followed by
  13. * - all elements of the collection coll
  14. * - separated by spaces
  15. */
  16. template <class T>
  17. inline void print_elements (const T& coll, const char* optcstr="")
  18. {
  19. typename T::const_iterator pos;
  20. std::cout << optcstr;
  21. for (pos=coll.begin(); pos!=coll.end(); ++pos) {
  22. std::cout << *pos << ' ';
  23. }
  24. std::cout << std::endl;
  25. }