1 | // ------------------------------------------------------------------------------ |
---|---|
2 | // format_test_enum.cpp : test format use with enums |
3 | // ------------------------------------------------------------------------------ |
4 | |
5 | // Copyright Steven Watanabe 2009. |
6 | // |
7 | // Distributed under the Boost Software License, Version 1.0. (See |
8 | // accompanying file LICENSE_1_0.txt or copy at |
9 | // http://www.boost.org/LICENSE_1_0.txt) |
10 | |
11 | // See http://www.boost.org/libs/format for library home page |
12 | |
13 | // ------------------------------------------------------------------------------ |
14 | |
15 | #include <boost/detail/lightweight_test.hpp> |
16 | #include <boost/format.hpp> |
17 | |
18 | enum enum_plain { PLAIN }; |
19 | enum { ANONYMOUS }; |
20 | enum enum_overloaded { OVERLOADED }; |
21 | typedef enum { OVERLOADED_TYPEDEF } enum_overloaded_typedef; |
22 | |
23 | std::ostream& operator<<(std::ostream& os, enum_overloaded) { |
24 | os << "overloaded"; |
25 | return(os); |
26 | } |
27 | |
28 | std::ostream& operator<<(std::ostream& os, enum_overloaded_typedef) { |
29 | os << "overloaded"; |
30 | return(os); |
31 | } |
32 | |
33 | int main(int, char*[]) { |
34 | // in this case, we should implicitly convert to int |
35 | BOOST_TEST_EQ((boost::format("%d") % PLAIN).str(), "0"); |
36 | BOOST_TEST_EQ((boost::format("%d") % ANONYMOUS).str(), "0"); |
37 | |
38 | // but here we need to use the overloaded operator |
39 | BOOST_TEST_EQ((boost::format("%s") % OVERLOADED).str(), "overloaded"); |
40 | BOOST_TEST_EQ((boost::format("%s") % OVERLOADED_TYPEDEF).str(), "overloaded"); |
41 | |
42 | return boost::report_errors(); |
43 | } |
44 |