forked from andreasbuhr/cppcoro
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathip_address.cpp
More file actions
27 lines (22 loc) · 711 Bytes
/
Copy pathip_address.cpp
File metadata and controls
27 lines (22 loc) · 711 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Lewis Baker
// Licenced under MIT license. See LICENSE.txt for details.
///////////////////////////////////////////////////////////////////////////////
#include <cppcoro/net/ip_address.hpp>
std::string cppcoro::net::ip_address::to_string() const
{
return is_ipv4() ? m_ipv4.to_string() : m_ipv6.to_string();
}
std::optional<cppcoro::net::ip_address>
cppcoro::net::ip_address::from_string(std::string_view string) noexcept
{
if (auto ipv4 = ipv4_address::from_string(string); ipv4)
{
return *ipv4;
}
if (auto ipv6 = ipv6_address::from_string(string); ipv6)
{
return *ipv6;
}
return std::nullopt;
}