From 20ed9f86282479567615f8c87be592e7eecf49ba Mon Sep 17 00:00:00 2001 From: qicosmos Date: Tue, 14 Feb 2023 16:44:52 +0800 Subject: [PATCH] check __cpp_lib_memory_resource (#200) --- include/easylog/easylog.h | 2 ++ include/easylog/record.hpp | 4 ++++ src/coro_rpc/CMakeLists.txt | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/include/easylog/easylog.h b/include/easylog/easylog.h index 41ae91d1..af96e27b 100644 --- a/include/easylog/easylog.h +++ b/include/easylog/easylog.h @@ -86,10 +86,12 @@ class logger { char buf[32]; size_t len = get_time_str(buf, record.get_time_point()); +#ifdef YLT_ENABLE_PMR #if __has_include() char arr[1024]; std::pmr::monotonic_buffer_resource resource(arr, 1024); std::pmr::string str{&resource}; +#endif #else std::string str; #endif diff --git a/include/easylog/record.hpp b/include/easylog/record.hpp index 7a8568fb..c7a5719f 100644 --- a/include/easylog/record.hpp +++ b/include/easylog/record.hpp @@ -154,10 +154,12 @@ class record_t { void printf_string_format(const char *fmt, Args... args) { size_t size = snprintf(nullptr, 0, fmt, args...); +#ifdef YLT_ENABLE_PMR #if __has_include() char arr[1024]; std::pmr::monotonic_buffer_resource resource(arr, 1024); std::pmr::string buf{&resource}; +#endif #else std::string buf; #endif @@ -195,10 +197,12 @@ class record_t { char buf_[64] = {}; size_t buf_len_ = 0; +#ifdef YLT_ENABLE_PMR #if __has_include() char arr_[1024]; std::pmr::monotonic_buffer_resource resource_; std::pmr::string ss_{&resource_}; +#endif #else std::string ss_; #endif diff --git a/src/coro_rpc/CMakeLists.txt b/src/coro_rpc/CMakeLists.txt index b4efc36b..b5cae31d 100644 --- a/src/coro_rpc/CMakeLists.txt +++ b/src/coro_rpc/CMakeLists.txt @@ -29,6 +29,11 @@ if (ENABLE_SSL) target_compile_definitions(coro_rpc INTERFACE ENABLE_SSL) target_link_libraries(coro_rpc INTERFACE OpenSSL::SSL OpenSSL::Crypto) endif () +option(ENABLE_PMR "Enable pmr support" OFF) +if (ENABLE_PMR) + message(STATUS "Use std::pmr") + target_compile_definitions(coro_rpc INTERFACE YLT_ENABLE_PMR) +endif () if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # When using coro_rpc_client, only remote function declarations are required. # Generally speaking, RPC function declaration and definition are divided.