iterator_range_io.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2009.
  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. // For more information, see http://www.boost.org/libs/range/
  9. //
  10. #ifndef BOOST_RANGE_ITERATOR_RANGE_IO_HPP_INCLUDED
  11. #define BOOST_RANGE_ITERATOR_RANGE_IO_HPP_INCLUDED
  12. #include <boost/config.hpp>
  13. #include <boost/detail/workaround.hpp>
  14. #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
  15. #pragma warning( push )
  16. #pragma warning( disable : 4996 )
  17. #endif
  18. // From boost/dynamic_bitset.hpp; thanks to Matthias Troyer for Cray X1 patch.
  19. #ifndef BOOST_OLD_IOSTREAMS
  20. # if defined(__STL_CONFIG_H) && \
  21. !defined (__STL_USE_NEW_IOSTREAMS) && !defined(__crayx1) \
  22. /**/
  23. # define BOOST_OLD_IOSTREAMS
  24. # endif
  25. #endif // #ifndef BOOST_OLD_IOSTREAMS
  26. #ifndef _STLP_NO_IOSTREAMS
  27. # ifndef BOOST_OLD_IOSTREAMS
  28. # include <ostream>
  29. # else
  30. # include <ostream.h>
  31. # endif
  32. #endif // _STLP_NO_IOSTREAMS
  33. #include <boost/range/iterator_range_core.hpp>
  34. #include <iterator>
  35. #include <algorithm>
  36. #include <cstddef>
  37. namespace boost
  38. {
  39. #ifndef _STLP_NO_IOSTREAMS
  40. # ifndef BOOST_OLD_IOSTREAMS
  41. //! iterator_range output operator
  42. /*!
  43. Output the range to an ostream. Elements are outputted
  44. in a sequence without separators.
  45. */
  46. template< typename IteratorT, typename Elem, typename Traits >
  47. inline std::basic_ostream<Elem,Traits>& operator<<(
  48. std::basic_ostream<Elem, Traits>& Os,
  49. const iterator_range<IteratorT>& r )
  50. {
  51. std::copy( r.begin(), r.end(),
  52. std::ostream_iterator< BOOST_DEDUCED_TYPENAME
  53. iterator_value<IteratorT>::type,
  54. Elem, Traits>(Os) );
  55. return Os;
  56. }
  57. # else
  58. //! iterator_range output operator
  59. /*!
  60. Output the range to an ostream. Elements are outputted
  61. in a sequence without separators.
  62. */
  63. template< typename IteratorT >
  64. inline std::ostream& operator<<(
  65. std::ostream& Os,
  66. const iterator_range<IteratorT>& r )
  67. {
  68. std::copy( r.begin(), r.end(), std::ostream_iterator<char>(Os));
  69. return Os;
  70. }
  71. # endif
  72. #endif // _STLP_NO_IOSTREAMS
  73. } // namespace boost
  74. #undef BOOST_OLD_IOSTREAMS
  75. #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
  76. #pragma warning(pop)
  77. #endif
  78. #endif // include guard