format_test_enum.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // ------------------------------------------------------------------------------
  2. // format_test_enum.cpp : test format use with enums
  3. // ------------------------------------------------------------------------------
  4. // Copyright Steven Watanabe 2009.
  5. //
  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. // See http://www.boost.org/libs/format for library home page
  10. // ------------------------------------------------------------------------------
  11. #include <boost/detail/lightweight_test.hpp>
  12. #include <boost/format.hpp>
  13. enum enum_plain { PLAIN };
  14. enum { ANONYMOUS };
  15. enum enum_overloaded { OVERLOADED };
  16. typedef enum { OVERLOADED_TYPEDEF } enum_overloaded_typedef;
  17. std::ostream& operator<<(std::ostream& os, enum_overloaded) {
  18. os << "overloaded";
  19. return(os);
  20. }
  21. std::ostream& operator<<(std::ostream& os, enum_overloaded_typedef) {
  22. os << "overloaded";
  23. return(os);
  24. }
  25. int main(int, char*[]) {
  26. // in this case, we should implicitly convert to int
  27. BOOST_TEST_EQ((boost::format("%d") % PLAIN).str(), "0");
  28. BOOST_TEST_EQ((boost::format("%d") % ANONYMOUS).str(), "0");
  29. // but here we need to use the overloaded operator
  30. BOOST_TEST_EQ((boost::format("%s") % OVERLOADED).str(), "overloaded");
  31. BOOST_TEST_EQ((boost::format("%s") % OVERLOADED_TYPEDEF).str(), "overloaded");
  32. return boost::report_errors();
  33. }