Skip to content

Commit

Permalink
check __cpp_lib_memory_resource (qicosmos#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos authored Feb 14, 2023
1 parent 32e265a commit 20ed9f8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/easylog/easylog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(<memory_resource>)
char arr[1024];
std::pmr::monotonic_buffer_resource resource(arr, 1024);
std::pmr::string str{&resource};
#endif
#else
std::string str;
#endif
Expand Down
4 changes: 4 additions & 0 deletions include/easylog/record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(<memory_resource>)
char arr[1024];
std::pmr::monotonic_buffer_resource resource(arr, 1024);
std::pmr::string buf{&resource};
#endif
#else
std::string buf;
#endif
Expand Down Expand Up @@ -195,10 +197,12 @@ class record_t {
char buf_[64] = {};
size_t buf_len_ = 0;

#ifdef YLT_ENABLE_PMR
#if __has_include(<memory_resource>)
char arr_[1024];
std::pmr::monotonic_buffer_resource resource_;
std::pmr::string ss_{&resource_};
#endif
#else
std::string ss_;
#endif
Expand Down
5 changes: 5 additions & 0 deletions src/coro_rpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 20ed9f8

Please sign in to comment.