network_v6.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // ip/impl/network_v6.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 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 ASIO_IP_IMPL_NETWORK_V6_HPP
  11. #define 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(ASIO_NO_IOSTREAM)
  16. #include "asio/detail/throw_error.hpp"
  17. #include "asio/detail/push_options.hpp"
  18. namespace asio {
  19. namespace ip {
  20. template <typename Elem, typename Traits>
  21. std::basic_ostream<Elem, Traits>& operator<<(
  22. std::basic_ostream<Elem, Traits>& os, const network_v6& addr)
  23. {
  24. asio::error_code ec;
  25. std::string s = addr.to_string(ec);
  26. if (ec)
  27. {
  28. if (os.exceptions() & std::basic_ostream<Elem, Traits>::failbit)
  29. asio::detail::throw_error(ec);
  30. else
  31. os.setstate(std::basic_ostream<Elem, Traits>::failbit);
  32. }
  33. else
  34. for (std::string::iterator i = s.begin(); i != s.end(); ++i)
  35. os << os.widen(*i);
  36. return os;
  37. }
  38. } // namespace ip
  39. } // namespace asio
  40. #include "asio/detail/pop_options.hpp"
  41. #endif // !defined(ASIO_NO_IOSTREAM)
  42. #endif // ASIO_IP_IMPL_NETWORK_V6_HPP