Improve vacpp support.
[boost.git] / boost / libs / tuple / test / io_test.cpp
blobd376534bfee7aad17bf4da82867622543a1e914d
1 // Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // For more information, see http://www.boost.org
9 // -- io_test.cpp -----------------------------------------------
11 // Testing the I/O facilities of tuples
13 #define BOOST_INCLUDE_MAIN // for testing, include rather than link
14 #include "boost/test/test_tools.hpp" // see "Header Implementation Option"
16 #include "boost/tuple/tuple_io.hpp"
17 #include "boost/tuple/tuple_comparison.hpp"
19 #include <fstream>
20 #include <iterator>
21 #include <algorithm>
22 #include <string>
24 #if defined BOOST_NO_STRINGSTREAM
25 #include <strstream>
26 #else
27 #include <sstream>
28 #endif
30 using namespace std;
31 using namespace boost;
33 #if defined BOOST_NO_STRINGSTREAM
34 typedef ostrstream useThisOStringStream;
35 typedef istrstream useThisIStringStream;
36 #else
37 typedef ostringstream useThisOStringStream;
38 typedef istringstream useThisIStringStream;
39 #endif
41 int test_main(int argc, char * argv[] ) {
42 (void)argc;
43 (void)argv;
44 using boost::tuples::set_close;
45 using boost::tuples::set_open;
46 using boost::tuples::set_delimiter;
48 useThisOStringStream os1;
50 // Set format [a, b, c] for os1
51 os1 << set_open('[');
52 os1 << set_close(']');
53 os1 << set_delimiter(',');
54 os1 << make_tuple(1, 2, 3);
55 BOOST_CHECK (os1.str() == std::string("[1,2,3]") );
58 useThisOStringStream os2;
59 // Set format (a:b:c) for os2;
60 os2 << set_open('(');
61 os2 << set_close(')');
62 os2 << set_delimiter(':');
63 #if !defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
64 os2 << make_tuple("TUPU", "HUPU", "LUPU", 4.5);
65 BOOST_CHECK (os2.str() == std::string("(TUPU:HUPU:LUPU:4.5)") );
66 #endif
69 // The format is still [a, b, c] for os1
70 os1 << make_tuple(1, 2, 3);
71 BOOST_CHECK (os1.str() == std::string("[1,2,3][1,2,3]") );
73 ofstream tmp("temp.tmp");
75 #if !defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
76 tmp << make_tuple("One", "Two", 3);
77 #endif
78 tmp << set_delimiter(':');
79 tmp << make_tuple(1000, 2000, 3000) << endl;
81 tmp.close();
83 // When teading tuples from a stream, manipulators must be set correctly:
84 ifstream tmp3("temp.tmp");
85 tuple<string, string, int> j;
87 #if !defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
88 tmp3 >> j;
89 BOOST_CHECK (tmp3.good() );
90 #endif
92 tmp3 >> set_delimiter(':');
93 tuple<int, int, int> i;
94 tmp3 >> i;
95 BOOST_CHECK (tmp3.good() );
97 tmp3.close();
100 // reading tuple<int, int, int> in format (a b c);
101 useThisIStringStream is("(100 200 300)");
103 tuple<int, int, int> ti;
104 BOOST_CHECK(bool(is >> ti));
105 BOOST_CHECK(ti == make_tuple(100, 200, 300));
108 // Note that strings are problematic:
109 // writing a tuple on a stream and reading it back doesn't work in
110 // general. If this is wanted, some kind of a parseable string class
111 // should be used.
113 return 0;