iostream_tests.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*=============================================================================
  2. Phoenix V1.2.1
  3. Copyright (c) 2001-2003 Joel de Guzman
  4. Use, modification and distribution is subject to the Boost Software
  5. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. ==============================================================================*/
  8. #include <iostream>
  9. #include <vector>
  10. #include <algorithm>
  11. #include <string>
  12. #include <boost/detail/lightweight_test.hpp>
  13. #include <boost/config.hpp>
  14. #ifdef BOOST_NO_STRINGSTREAM
  15. #include <strstream>
  16. #define SSTREAM strstream
  17. std::string GETSTRING(std::strstream& ss)
  18. {
  19. ss << ends;
  20. std::string rval = ss.str();
  21. ss.freeze(false);
  22. return rval;
  23. }
  24. #else
  25. #include <sstream>
  26. #define GETSTRING(ss) ss.str()
  27. #define SSTREAM stringstream
  28. #endif
  29. //#define PHOENIX_LIMIT 15
  30. #include <boost/spirit/include/phoenix1_primitives.hpp>
  31. #include <boost/spirit/include/phoenix1_composite.hpp>
  32. #include <boost/spirit/include/phoenix1_operators.hpp>
  33. #include <boost/spirit/include/phoenix1_special_ops.hpp>
  34. using namespace phoenix;
  35. using namespace std;
  36. ///////////////////////////////////////////////////////////////////////////////
  37. int
  38. main()
  39. {
  40. int i100 = 100;
  41. string hello = "hello";
  42. const char* world = " world";
  43. ///////////////////////////////////////////////////////////////////////////////
  44. //
  45. // IO streams
  46. //
  47. ///////////////////////////////////////////////////////////////////////////////
  48. vector<int> v;
  49. v.push_back(1);
  50. v.push_back(2);
  51. v.push_back(3);
  52. v.push_back(4);
  53. v.push_back(5);
  54. char const* msg = "cout assert\n";
  55. (cout << arg1)(msg);
  56. (cout << val(hello) << world << ", you da man!\n")();
  57. for_each(v.begin(), v.end(), cout << arg1 << ',');
  58. cout << endl;
  59. #ifdef __BORLANDC__ // *** See special_ops.hpp why ***
  60. (cout << arg1 << "this is it, shukz:" << hex_ << arg2 << endl_ << endl_)(msg, i100);
  61. #else
  62. (cout << arg1 << "this is it, shukz:" << hex << arg2 << endl << endl)(msg, i100);
  63. #endif
  64. int in;
  65. int out = 12345;
  66. SSTREAM sstr;
  67. (sstr << arg1)(out);
  68. (sstr >> arg1)(in);
  69. BOOST_TEST(in == out);
  70. ///////////////////////////////////////////////////////////////////////////////
  71. //
  72. // End asserts
  73. //
  74. ///////////////////////////////////////////////////////////////////////////////
  75. return boost::report_errors();
  76. }