network_v6.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // ip/impl/network_v6.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_IP_IMPL_NETWORK_V6_HPP
  11. #define BOOST_ASIO_IP_IMPL_NETWORK_V6_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #if !defined(BOOST_ASIO_NO_IOSTREAM)
  16. #include <boost/asio/detail/throw_error.hpp>
  17. #include <boost/asio/detail/push_options.hpp>
  18. namespace boost {
  19. namespace asio {
  20. namespace ip {
  21. template <typename Elem, typename Traits>
  22. std::basic_ostream<Elem, Traits>& operator<<(
  23. std::basic_ostream<Elem, Traits>& os, const network_v6& addr)
  24. {
  25. boost::system::error_code ec;
  26. std::string s = addr.to_string(ec);
  27. if (ec)
  28. {
  29. if (os.exceptions() & std::basic_ostream<Elem, Traits>::failbit)
  30. boost::asio::detail::throw_error(ec);
  31. else
  32. os.setstate(std::basic_ostream<Elem, Traits>::failbit);
  33. }
  34. else
  35. for (std::string::iterator i = s.begin(); i != s.end(); ++i)
  36. os << os.widen(*i);
  37. return os;
  38. }
  39. } // namespace ip
  40. } // namespace asio
  41. } // namespace boost
  42. #include <boost/asio/detail/pop_options.hpp>
  43. #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
  44. #endif // BOOST_ASIO_IP_IMPL_NETWORK_V6_HPP