From a555e6847e93f8501be812840ef72ab4bf609938 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 7 Dec 2024 10:46:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9c++11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Network/UdpServer.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Network/UdpServer.h b/src/Network/UdpServer.h index 7e4eb06d..a5151f70 100644 --- a/src/Network/UdpServer.h +++ b/src/Network/UdpServer.h @@ -11,7 +11,10 @@ #ifndef TOOLKIT_NETWORK_UDPSERVER_H #define TOOLKIT_NETWORK_UDPSERVER_H +#if __cplusplus >= 201703L +#include #include +#endif #include "Server.h" #include "Session.h" @@ -19,8 +22,17 @@ namespace toolkit { class UdpServer : public Server { public: +#if __cplusplus >= 201703L class PeerIdType : public std::array { +#else + class PeerIdType : public std::string { +#endif public: +#if __cplusplus < 201703L + PeerIdType() { + resize(18); + } +#endif bool operator==(const PeerIdType &that) const { return as(0) == that.as(0) && as(8) == that.as(8) && @@ -91,7 +103,11 @@ class UdpServer : public Server { private: struct PeerIdHash { +#if __cplusplus >= 201703L size_t operator()(const PeerIdType &v) const noexcept { return std::hash {}(std::string_view(v.data(), v.size())); } +#else + size_t operator()(const PeerIdType &v) const noexcept { return std::hash {}(v); } +#endif }; using SessionMapType = std::unordered_map;