io.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // (C) Copyright Gennadiy Rozental 2001.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/test for the library home page.
  6. //
  7. // File : $RCSfile$
  8. //
  9. // Version : $Revision$
  10. //
  11. // Description : basic_cstring i/o implementation
  12. // ***************************************************************************
  13. #ifndef BOOST_TEST_UTILS_BASIC_CSTRING_IO_HPP
  14. #define BOOST_TEST_UTILS_BASIC_CSTRING_IO_HPP
  15. // Boost.Test
  16. #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
  17. // STL
  18. #include <iosfwd>
  19. #include <string>
  20. #include <boost/test/detail/suppress_warnings.hpp>
  21. //____________________________________________________________________________//
  22. namespace boost {
  23. namespace unit_test {
  24. #ifdef BOOST_CLASSIC_IOSTREAMS
  25. template<typename CharT>
  26. inline std::ostream&
  27. operator<<( std::ostream& os, basic_cstring<CharT> const& str )
  28. {
  29. typedef typename ut_detail::bcs_base_char<CharT>::type char_type;
  30. char_type const* const beg = reinterpret_cast<char_type const* const>( str.begin() );
  31. char_type const* const end = reinterpret_cast<char_type const* const>( str.end() );
  32. os << std::basic_string<char_type>( beg, end - beg );
  33. return os;
  34. }
  35. #else
  36. template<typename CharT1, typename Tr,typename CharT2>
  37. inline std::basic_ostream<CharT1,Tr>&
  38. operator<<( std::basic_ostream<CharT1,Tr>& os, basic_cstring<CharT2> const& str )
  39. {
  40. CharT1 const* const beg = reinterpret_cast<CharT1 const*>( str.begin() ); // !!
  41. CharT1 const* const end = reinterpret_cast<CharT1 const*>( str.end() );
  42. os << std::basic_string<CharT1,Tr>( beg, end - beg );
  43. return os;
  44. }
  45. #endif
  46. //____________________________________________________________________________//
  47. } // namespace unit_test
  48. } // namespace boost
  49. //____________________________________________________________________________//
  50. #include <boost/test/detail/enable_warnings.hpp>
  51. #endif // BOOST_TEST_BASIC_CSTRING_IO_HPP_071894GER