From 61eb6007bd21fe3343fff07eccc91c9b8a9c5438 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Thu, 18 Jul 2024 20:31:49 +0200 Subject: [PATCH 01/28] std::format support for dpp::snowflake --- include/dpp/snowflake.h | 23 +++++++++++++++++++++++ src/unittest/test.cpp | 15 +++++++++++++++ src/unittest/test.h | 3 +++ 3 files changed, 41 insertions(+) diff --git a/include/dpp/snowflake.h b/include/dpp/snowflake.h index a2c5496625..42f2845d87 100644 --- a/include/dpp/snowflake.h +++ b/include/dpp/snowflake.h @@ -281,3 +281,26 @@ struct std::hash return std::hash{}(s.value); } }; + +#if __cplusplus >= 202002L +#if defined(__cpp_lib_format) || __has_include() //fix for https://github.com/llvm/llvm-project/issues/77773 +#include + +/* + * @brief implementation of formater for dpp::snowlfake for std::format support + * https://en.cppreference.com/w/cpp/utility/format/formatter + */ +template <> +struct std::formatter +{ + constexpr auto parse(std::format_parse_context& ctx) { + return ctx.begin(); + } + + auto format(const dpp::snowflake& snowflake, std::format_context& ctx) const { + return std::format_to(ctx.out(), "{}", snowflake.str()); + } +}; + +#endif // __cpp_lib_format +#endif // __cplusplus >= 202002L \ No newline at end of file diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index 64440d4fcc..6e5807b3e4 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -379,6 +379,21 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b set_test(SNOWFLAKE, success); } + { // test snowlfake: std::format support + + #if __cplusplus >= 202002L + #if defined(__cpp_lib_format) || __has_include() //fix for https://github.com/llvm/llvm-project/issues/77773 + start_test(SNOWLAKE_STD_FORMAT); + set_test(SNOWLAKE_STD_FORMAT, + std::format("{}",dpp::snowflake{}) == "0" && + std::format("{}",dpp::snowflake{12345}) == "12345" && + std::format("{} hello {}", dpp::snowflake{12345}, dpp::snowflake{54321}) == "12345 hello 54321" + ); + + #endif // __cpp_lib_format + #endif // __cplusplus >= 202002L + }; + { // test dpp::json_interface start_test(JSON_INTERFACE); struct fillable : dpp::json_interface { diff --git a/src/unittest/test.h b/src/unittest/test.h index 8bb15af894..131f436dfa 100644 --- a/src/unittest/test.h +++ b/src/unittest/test.h @@ -263,6 +263,9 @@ DPP_TEST(CORO_EVENT_HANDLER, "coro: online event handler", tf_online | tf_coro); DPP_TEST(CORO_API_CALLS, "coro: online api calls", tf_online | tf_coro); DPP_TEST(CORO_MUMBO_JUMBO, "coro: online mumbo jumbo in event handler", tf_online | tf_coro | tf_extended); +DPP_TEST(SNOWLAKE_STD_FORMAT, "snowlfake: std::format support", tf_offline); + + void coro_offline_tests(); void coro_online_tests(dpp::cluster *bot); From 9bdb1fd3b0af807646708cadde0cb2edcaf74dce Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Thu, 18 Jul 2024 20:35:28 +0200 Subject: [PATCH 02/28] fixed padding in tests --- src/unittest/test.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/unittest/test.h b/src/unittest/test.h index 131f436dfa..6d956a7e7b 100644 --- a/src/unittest/test.h +++ b/src/unittest/test.h @@ -265,7 +265,6 @@ DPP_TEST(CORO_MUMBO_JUMBO, "coro: online mumbo jumbo in event handler", tf_onlin DPP_TEST(SNOWLAKE_STD_FORMAT, "snowlfake: std::format support", tf_offline); - void coro_offline_tests(); void coro_online_tests(dpp::cluster *bot); From 15ada2e4b2a399a12c80a3643d4492972135381b Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Thu, 18 Jul 2024 20:39:51 +0200 Subject: [PATCH 03/28] spelling fix --- src/unittest/test.cpp | 6 +++--- src/unittest/test.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index 6e5807b3e4..090cabc9dd 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -379,12 +379,12 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b set_test(SNOWFLAKE, success); } - { // test snowlfake: std::format support + { // test snowflake: std::format support #if __cplusplus >= 202002L #if defined(__cpp_lib_format) || __has_include() //fix for https://github.com/llvm/llvm-project/issues/77773 - start_test(SNOWLAKE_STD_FORMAT); - set_test(SNOWLAKE_STD_FORMAT, + start_test(SNOWFLAKE_STD_FORMAT); + set_test(SNOWFLAKE_STD_FORMAT, std::format("{}",dpp::snowflake{}) == "0" && std::format("{}",dpp::snowflake{12345}) == "12345" && std::format("{} hello {}", dpp::snowflake{12345}, dpp::snowflake{54321}) == "12345 hello 54321" diff --git a/src/unittest/test.h b/src/unittest/test.h index 6d956a7e7b..0560aebc9b 100644 --- a/src/unittest/test.h +++ b/src/unittest/test.h @@ -263,7 +263,7 @@ DPP_TEST(CORO_EVENT_HANDLER, "coro: online event handler", tf_online | tf_coro); DPP_TEST(CORO_API_CALLS, "coro: online api calls", tf_online | tf_coro); DPP_TEST(CORO_MUMBO_JUMBO, "coro: online mumbo jumbo in event handler", tf_online | tf_coro | tf_extended); -DPP_TEST(SNOWLAKE_STD_FORMAT, "snowlfake: std::format support", tf_offline); +DPP_TEST(SNOWFLAKE_STD_FORMAT, "snowflake: std::format support", tf_offline); void coro_offline_tests(); void coro_online_tests(dpp::cluster *bot); From 2aca0adbf8303e7440f29508d085127daa38a016 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Thu, 18 Jul 2024 21:08:04 +0200 Subject: [PATCH 04/28] fixing test not running fail on older compilers and theoretical fix for mac os clang14 by disabling formatting --- include/dpp/snowflake.h | 6 +++++- src/unittest/test.cpp | 13 +++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/dpp/snowflake.h b/include/dpp/snowflake.h index 42f2845d87..46e2bc8c9a 100644 --- a/include/dpp/snowflake.h +++ b/include/dpp/snowflake.h @@ -283,7 +283,11 @@ struct std::hash }; #if __cplusplus >= 202002L -#if defined(__cpp_lib_format) || __has_include() //fix for https://github.com/llvm/llvm-project/issues/77773 +//fix for https://github.com/llvm/llvm-project/issues/77773 and +// apple support on clang 14 https://developer.apple.com/xcode/cpp/ +#if defined(__cpp_lib_format) || \ + (__has_include()&& (!defined(__clang__) || \ + (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || __clang_major__ >=14)))) #include /* diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index 090cabc9dd..be89bebf09 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -382,15 +382,24 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b { // test snowflake: std::format support #if __cplusplus >= 202002L - #if defined(__cpp_lib_format) || __has_include() //fix for https://github.com/llvm/llvm-project/issues/77773 - start_test(SNOWFLAKE_STD_FORMAT); + + //fix for https://github.com/llvm/llvm-project/issues/77773 and + // apple support on clang 14 https://developer.apple.com/xcode/cpp/ + #if defined(__cpp_lib_format) || \ + (__has_include()&& (!defined(__clang__) || \ + (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || __clang_major__ >=14)))) set_test(SNOWFLAKE_STD_FORMAT, std::format("{}",dpp::snowflake{}) == "0" && std::format("{}",dpp::snowflake{12345}) == "12345" && std::format("{} hello {}", dpp::snowflake{12345}, dpp::snowflake{54321}) == "12345 hello 54321" ); + #else + set_status(SNOWFLAKE_STD_FORMAT,ts_skipped); #endif // __cpp_lib_format + + #else + set_status(SNOWFLAKE_STD_FORMAT,ts_skipped); #endif // __cplusplus >= 202002L }; From 0e31ace3fea748a5bbfcdddee4596619df3d92e1 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Thu, 18 Jul 2024 21:11:50 +0200 Subject: [PATCH 05/28] one more fix of conditions for formatting --- include/dpp/snowflake.h | 2 +- src/unittest/test.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/dpp/snowflake.h b/include/dpp/snowflake.h index 46e2bc8c9a..26a0306529 100644 --- a/include/dpp/snowflake.h +++ b/include/dpp/snowflake.h @@ -287,7 +287,7 @@ struct std::hash // apple support on clang 14 https://developer.apple.com/xcode/cpp/ #if defined(__cpp_lib_format) || \ (__has_include()&& (!defined(__clang__) || \ - (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || __clang_major__ >=14)))) + (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || (__clang_major__ >=14 && !defined(__APPLE__))))) #include /* diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index be89bebf09..ee794b06c2 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -386,8 +386,8 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b //fix for https://github.com/llvm/llvm-project/issues/77773 and // apple support on clang 14 https://developer.apple.com/xcode/cpp/ #if defined(__cpp_lib_format) || \ - (__has_include()&& (!defined(__clang__) || \ - (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || __clang_major__ >=14)))) + (__has_include()&& (!defined(__clang__) || \ + (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || (__clang_major__ >=14 && !defined(__APPLE__))))) set_test(SNOWFLAKE_STD_FORMAT, std::format("{}",dpp::snowflake{}) == "0" && std::format("{}",dpp::snowflake{12345}) == "12345" && From eb743d5e6a620420a756d2b1a289f13e50ac3a8d Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Thu, 18 Jul 2024 21:14:10 +0200 Subject: [PATCH 06/28] one more fix of conditions for formatting --- include/dpp/snowflake.h | 2 +- src/unittest/test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/dpp/snowflake.h b/include/dpp/snowflake.h index 26a0306529..bc51dc42d4 100644 --- a/include/dpp/snowflake.h +++ b/include/dpp/snowflake.h @@ -287,7 +287,7 @@ struct std::hash // apple support on clang 14 https://developer.apple.com/xcode/cpp/ #if defined(__cpp_lib_format) || \ (__has_include()&& (!defined(__clang__) || \ - (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || (__clang_major__ >=14 && !defined(__APPLE__))))) + (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || (__clang_major__ >=14 && !defined(__APPLE__)))))) #include /* diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index ee794b06c2..289149bd6c 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -387,7 +387,7 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b // apple support on clang 14 https://developer.apple.com/xcode/cpp/ #if defined(__cpp_lib_format) || \ (__has_include()&& (!defined(__clang__) || \ - (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || (__clang_major__ >=14 && !defined(__APPLE__))))) + (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || (__clang_major__ >=14 && !defined(__APPLE__)))))) set_test(SNOWFLAKE_STD_FORMAT, std::format("{}",dpp::snowflake{}) == "0" && std::format("{}",dpp::snowflake{12345}) == "12345" && From 0659f8ba4f85acf13545fee76f34943189340a74 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Thu, 18 Jul 2024 21:21:10 +0200 Subject: [PATCH 07/28] one more fix of conditions for formatting --- include/dpp/snowflake.h | 6 +++--- src/unittest/test.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/dpp/snowflake.h b/include/dpp/snowflake.h index bc51dc42d4..f733a80e2f 100644 --- a/include/dpp/snowflake.h +++ b/include/dpp/snowflake.h @@ -285,9 +285,9 @@ struct std::hash #if __cplusplus >= 202002L //fix for https://github.com/llvm/llvm-project/issues/77773 and // apple support on clang 14 https://developer.apple.com/xcode/cpp/ -#if defined(__cpp_lib_format) || \ - (__has_include()&& (!defined(__clang__) || \ - (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || (__clang_major__ >=14 && !defined(__APPLE__)))))) +#if (!defined(__clang__) || \ + (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || (__clang_major__ >= 14 && !defined(__APPLE__))))) && (defined(__cpp_lib_format) || \ + (__has_include()) #include /* diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index 289149bd6c..1fbdd932e9 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -385,9 +385,9 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b //fix for https://github.com/llvm/llvm-project/issues/77773 and // apple support on clang 14 https://developer.apple.com/xcode/cpp/ - #if defined(__cpp_lib_format) || \ - (__has_include()&& (!defined(__clang__) || \ - (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || (__clang_major__ >=14 && !defined(__APPLE__)))))) + #if (!defined(__clang__) || \ + (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || (__clang_major__ >= 14 && !defined(__APPLE__))))) && (defined(__cpp_lib_format) || \ + (__has_include()) set_test(SNOWFLAKE_STD_FORMAT, std::format("{}",dpp::snowflake{}) == "0" && std::format("{}",dpp::snowflake{12345}) == "12345" && From 115f1dd497a14f5c9f3a8fba497b6179d4745806 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Thu, 18 Jul 2024 21:23:27 +0200 Subject: [PATCH 08/28] one more fix of conditions for formatting --- include/dpp/snowflake.h | 2 +- src/unittest/test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/dpp/snowflake.h b/include/dpp/snowflake.h index f733a80e2f..a651bd417e 100644 --- a/include/dpp/snowflake.h +++ b/include/dpp/snowflake.h @@ -287,7 +287,7 @@ struct std::hash // apple support on clang 14 https://developer.apple.com/xcode/cpp/ #if (!defined(__clang__) || \ (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || (__clang_major__ >= 14 && !defined(__APPLE__))))) && (defined(__cpp_lib_format) || \ - (__has_include()) + (__has_include())) #include /* diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index 1fbdd932e9..05787bac31 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -387,7 +387,7 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b // apple support on clang 14 https://developer.apple.com/xcode/cpp/ #if (!defined(__clang__) || \ (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || (__clang_major__ >= 14 && !defined(__APPLE__))))) && (defined(__cpp_lib_format) || \ - (__has_include()) + (__has_include())) set_test(SNOWFLAKE_STD_FORMAT, std::format("{}",dpp::snowflake{}) == "0" && std::format("{}",dpp::snowflake{12345}) == "12345" && From 1a70ef2bd37279ed4657758fb7efdd3c54ece281 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Thu, 18 Jul 2024 23:14:37 +0200 Subject: [PATCH 09/28] one more fix of conditions for formatting --- include/dpp/snowflake.h | 7 +++---- src/unittest/test.cpp | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/include/dpp/snowflake.h b/include/dpp/snowflake.h index a651bd417e..1f30e17f41 100644 --- a/include/dpp/snowflake.h +++ b/include/dpp/snowflake.h @@ -285,13 +285,12 @@ struct std::hash #if __cplusplus >= 202002L //fix for https://github.com/llvm/llvm-project/issues/77773 and // apple support on clang 14 https://developer.apple.com/xcode/cpp/ -#if (!defined(__clang__) || \ - (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || (__clang_major__ >= 14 && !defined(__APPLE__))))) && (defined(__cpp_lib_format) || \ - (__has_include())) +#if (defined(__cpp_lib_format) || \ + (defined(__clang__) && __clang_major__ >= 14 && !defined(__APPLE__) && __has_include())) #include /* - * @brief implementation of formater for dpp::snowlfake for std::format support + * @brief implementation of formater for dpp::snowflake for std::format support * https://en.cppreference.com/w/cpp/utility/format/formatter */ template <> diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index 05787bac31..5f96c7024f 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -385,9 +385,9 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b //fix for https://github.com/llvm/llvm-project/issues/77773 and // apple support on clang 14 https://developer.apple.com/xcode/cpp/ - #if (!defined(__clang__) || \ - (defined(__clang__) && ((__clang_major__ >= 15 && defined(__APPLE__)) || (__clang_major__ >= 14 && !defined(__APPLE__))))) && (defined(__cpp_lib_format) || \ - (__has_include())) + #if (defined(__cpp_lib_format) || \ + (defined(__clang__) && __clang_major__ >= 14 && !defined(__APPLE__) && __has_include())) + set_test(SNOWFLAKE_STD_FORMAT, std::format("{}",dpp::snowflake{}) == "0" && std::format("{}",dpp::snowflake{12345}) == "12345" && @@ -800,7 +800,7 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b m5.get_url() == "" && m6.get_url() == "" && m7.get_url() == "" && - m8.get_url() == "" + m8.get_url() == "" ); } @@ -910,31 +910,31 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b set_test(UTILITY_USER_URL, false); auto user_url = dpp::utility::user_url(123); - set_test(UTILITY_USER_URL, - user_url == dpp::utility::url_host + "/users/123" && + set_test(UTILITY_USER_URL, + user_url == dpp::utility::url_host + "/users/123" && dpp::utility::user_url(0) == "" ); set_test(UTILITY_MESSAGE_URL, false); auto message_url = dpp::utility::message_url(1,2,3); set_test(UTILITY_MESSAGE_URL, - message_url == dpp::utility::url_host+ "/channels/1/2/3" && + message_url == dpp::utility::url_host+ "/channels/1/2/3" && dpp::utility::message_url(0,2,3) == "" && - dpp::utility::message_url(1,0,3) == "" && + dpp::utility::message_url(1,0,3) == "" && dpp::utility::message_url(1,2,0) == "" && dpp::utility::message_url(0,0,3) == "" && dpp::utility::message_url(0,2,0) == "" && dpp::utility::message_url(1,0,0) == "" && - dpp::utility::message_url(0,0,0) == "" + dpp::utility::message_url(0,0,0) == "" ); set_test(UTILITY_CHANNEL_URL, false); auto channel_url = dpp::utility::channel_url(1,2); - set_test(UTILITY_CHANNEL_URL, + set_test(UTILITY_CHANNEL_URL, channel_url == dpp::utility::url_host+ "/channels/1/2" && dpp::utility::channel_url(0,2) == "" && dpp::utility::channel_url(1,0) == "" && - dpp::utility::channel_url(0,0) == "" + dpp::utility::channel_url(0,0) == "" ); set_test(UTILITY_THREAD_URL, false); @@ -943,7 +943,7 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b thread_url == dpp::utility::url_host+ "/channels/1/2" && dpp::utility::thread_url(0,2) == "" && dpp::utility::thread_url(1,0) == "" && - dpp::utility::thread_url(0,0) == "" + dpp::utility::thread_url(0,0) == "" ); } @@ -1672,7 +1672,7 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b set_test(TIMESTAMP, false); } } else { - set_test(MESSAGESGET, false); + set_test(MESSAGESGET, false); } } else { set_test(MESSAGESGET, false); From 792e1d065e873da32dfc4c8521d8d534efd11ce1 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Fri, 19 Jul 2024 00:26:00 +0200 Subject: [PATCH 10/28] try to specify types to fix g++ compilation --- CMakeLists.txt | 11 ++++++++++- include/dpp/snowflake.h | 6 ++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 025203badf..9c265568b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,11 +24,20 @@ option(RUN_LDCONFIG "Run ldconfig after installation" ON) option(DPP_INSTALL "Generate the install target" ON) option(DPP_BUILD_TEST "Build the test program" ON) option(DPP_NO_VCPKG "No VCPKG" OFF) -option(DPP_CORO "Experimental support for C++20 coroutines" OFF) +option(DPP_CORO "Experimental support for C++20 coroutines" ON) option(DPP_USE_EXTERNAL_JSON "Use an external installation of nlohmann::json" OFF) option(DPP_USE_PCH "Use precompiled headers to speed up compilation" OFF) option(AVX_TYPE "Force AVX type for speeding up audio mixing" OFF) +add_link_options( + -stdlib=libc++ + -L/usr/lib/llvm-19/lib + -Wl,-rpath,/usr/lib/llvm-19/lib + -Wdocumentation + -Wno-unused-value +) + + include(CheckCXXSymbolExists) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) add_compile_definitions(DPP_BUILD) diff --git a/include/dpp/snowflake.h b/include/dpp/snowflake.h index 1f30e17f41..f2ac9786d1 100644 --- a/include/dpp/snowflake.h +++ b/include/dpp/snowflake.h @@ -296,11 +296,13 @@ struct std::hash template <> struct std::formatter { - constexpr auto parse(std::format_parse_context& ctx) { + template + constexpr TP::iterator parse(TP& ctx) { return ctx.begin(); } - auto format(const dpp::snowflake& snowflake, std::format_context& ctx) const { + template + TF::iterator format(const dpp::snowflake& snowflake, TF& ctx) const { return std::format_to(ctx.out(), "{}", snowflake.str()); } }; From fd4bd762711a64d769ed0b8333ec7aa420066190 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Fri, 19 Jul 2024 00:30:09 +0200 Subject: [PATCH 11/28] clean addition cmake --- CMakeLists.txt | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c265568b0..025203badf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,20 +24,11 @@ option(RUN_LDCONFIG "Run ldconfig after installation" ON) option(DPP_INSTALL "Generate the install target" ON) option(DPP_BUILD_TEST "Build the test program" ON) option(DPP_NO_VCPKG "No VCPKG" OFF) -option(DPP_CORO "Experimental support for C++20 coroutines" ON) +option(DPP_CORO "Experimental support for C++20 coroutines" OFF) option(DPP_USE_EXTERNAL_JSON "Use an external installation of nlohmann::json" OFF) option(DPP_USE_PCH "Use precompiled headers to speed up compilation" OFF) option(AVX_TYPE "Force AVX type for speeding up audio mixing" OFF) -add_link_options( - -stdlib=libc++ - -L/usr/lib/llvm-19/lib - -Wl,-rpath,/usr/lib/llvm-19/lib - -Wdocumentation - -Wno-unused-value -) - - include(CheckCXXSymbolExists) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) add_compile_definitions(DPP_BUILD) From 7a9d8e0cb60780d1108ffbe6d11748aa337c79a4 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Fri, 19 Jul 2024 02:47:24 +0200 Subject: [PATCH 12/28] g++ compilation fix --- include/dpp/snowflake.h | 11 ++++++----- src/unittest/test.cpp | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/dpp/snowflake.h b/include/dpp/snowflake.h index f2ac9786d1..3ed1240015 100644 --- a/include/dpp/snowflake.h +++ b/include/dpp/snowflake.h @@ -286,7 +286,8 @@ struct std::hash //fix for https://github.com/llvm/llvm-project/issues/77773 and // apple support on clang 14 https://developer.apple.com/xcode/cpp/ #if (defined(__cpp_lib_format) || \ - (defined(__clang__) && __clang_major__ >= 14 && !defined(__APPLE__) && __has_include())) + (defined(__clang__) && __clang_major__ >= 14 && !defined(__APPLE__) && __has_include())) || ( defined(__GNUC__) && __GNUC__ >= 13) + #include /* @@ -297,13 +298,13 @@ template <> struct std::formatter { template - constexpr TP::iterator parse(TP& ctx) { - return ctx.begin(); + constexpr typename TP::iterator parse(TP& ctx) { + return ctx.begin(); } template - TF::iterator format(const dpp::snowflake& snowflake, TF& ctx) const { - return std::format_to(ctx.out(), "{}", snowflake.str()); + typename TF::iterator format(const dpp::snowflake& snowflake, TF& ctx) const { + return std::format_to(ctx.out(), "{}", snowflake.str()); } }; diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index 5f96c7024f..eaa8eb5999 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -386,7 +386,7 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b //fix for https://github.com/llvm/llvm-project/issues/77773 and // apple support on clang 14 https://developer.apple.com/xcode/cpp/ #if (defined(__cpp_lib_format) || \ - (defined(__clang__) && __clang_major__ >= 14 && !defined(__APPLE__) && __has_include())) + (defined(__clang__) && __clang_major__ >= 14 && !defined(__APPLE__) && __has_include())) || ( defined(__GNUC__) && __GNUC__ >= 13) set_test(SNOWFLAKE_STD_FORMAT, std::format("{}",dpp::snowflake{}) == "0" && From e1dec281edca3ff7b03d7dbb7adf5a7fee7e5f0e Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Fri, 19 Jul 2024 13:57:13 +0200 Subject: [PATCH 13/28] introduced DPP_HAS_FORMAT definition --- include/dpp/snowflake.h | 26 +++++++++++++++----------- src/unittest/test.cpp | 15 ++------------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/include/dpp/snowflake.h b/include/dpp/snowflake.h index 3ed1240015..1142d00459 100644 --- a/include/dpp/snowflake.h +++ b/include/dpp/snowflake.h @@ -26,6 +26,19 @@ #include #include +#if __cplusplus >= 202002L +//fix for https://github.com/llvm/llvm-project/issues/77773 and +// apple support on clang 14 https://developer.apple.com/xcode/cpp/ +#if (defined(__cpp_lib_format) || \ + (defined(__clang__) && __clang_major__ >= 14 && !defined(__APPLE__) && __has_include())) || ( defined(__GNUC__) && __GNUC__ >= 13) + +#define DPP_HAS_FORMAT + +#include + +#endif +#endif + /** * @brief The main namespace for D++ functions. classes and types */ @@ -282,14 +295,7 @@ struct std::hash } }; -#if __cplusplus >= 202002L -//fix for https://github.com/llvm/llvm-project/issues/77773 and -// apple support on clang 14 https://developer.apple.com/xcode/cpp/ -#if (defined(__cpp_lib_format) || \ - (defined(__clang__) && __clang_major__ >= 14 && !defined(__APPLE__) && __has_include())) || ( defined(__GNUC__) && __GNUC__ >= 13) - -#include - +#ifdef DPP_HAS_FORMAT /* * @brief implementation of formater for dpp::snowflake for std::format support * https://en.cppreference.com/w/cpp/utility/format/formatter @@ -307,6 +313,4 @@ struct std::formatter return std::format_to(ctx.out(), "{}", snowflake.str()); } }; - -#endif // __cpp_lib_format -#endif // __cplusplus >= 202002L \ No newline at end of file +#endif //DPP_HAS_FORMAT \ No newline at end of file diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index eaa8eb5999..33dddc3d1c 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -381,26 +381,15 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b { // test snowflake: std::format support - #if __cplusplus >= 202002L - - //fix for https://github.com/llvm/llvm-project/issues/77773 and - // apple support on clang 14 https://developer.apple.com/xcode/cpp/ - #if (defined(__cpp_lib_format) || \ - (defined(__clang__) && __clang_major__ >= 14 && !defined(__APPLE__) && __has_include())) || ( defined(__GNUC__) && __GNUC__ >= 13) - + #ifdef DPP_HAS_FORMAT set_test(SNOWFLAKE_STD_FORMAT, std::format("{}",dpp::snowflake{}) == "0" && std::format("{}",dpp::snowflake{12345}) == "12345" && std::format("{} hello {}", dpp::snowflake{12345}, dpp::snowflake{54321}) == "12345 hello 54321" ); - - #else - set_status(SNOWFLAKE_STD_FORMAT,ts_skipped); - #endif // __cpp_lib_format - #else set_status(SNOWFLAKE_STD_FORMAT,ts_skipped); - #endif // __cplusplus >= 202002L + #endif // DPP_HAS_FORMAT }; { // test dpp::json_interface From fa7a831346a4c7ca94f333bd8c3f680f0f7d65b7 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Fri, 19 Jul 2024 16:04:20 +0200 Subject: [PATCH 14/28] cmake check for format --- CMakeLists.txt | 42 ++++++++++++++++++++++++++++++++++++++++- include/dpp/snowflake.h | 12 ++---------- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 025203badf..85f4547080 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ option(RUN_LDCONFIG "Run ldconfig after installation" ON) option(DPP_INSTALL "Generate the install target" ON) option(DPP_BUILD_TEST "Build the test program" ON) option(DPP_NO_VCPKG "No VCPKG" OFF) -option(DPP_CORO "Experimental support for C++20 coroutines" OFF) +option(DPP_CORO "Experimental support for C++20 coroutines" ON) option(DPP_USE_EXTERNAL_JSON "Use an external installation of nlohmann::json" OFF) option(DPP_USE_PCH "Use precompiled headers to speed up compilation" OFF) option(AVX_TYPE "Force AVX type for speeding up audio mixing" OFF) @@ -115,3 +115,43 @@ else() # that made no sense, it seems they may have changed their parsing rules somehow. message("-- Using bundled nlohmann::json") endif() + +if ("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES) + include(CheckCXXSourceCompiles) + unset(HAS_FORMAT CACHE) + set(temp_flags "${CMAKE_REQUIRED_FLAGS}") + set(CMAKE_REQUIRED_FLAGS "-std=c++20") + check_cxx_source_compiles( + " + #include + #include + + struct MyType { + int value; + std::string str() const { return std::to_string(value); } + }; + + template <> + struct std::formatter : std::formatter { + auto format(const MyType& item, std::format_context& ctx) const -> decltype(ctx.out()) { + return std::format_to(ctx.out(), \"{}\", item.str()); + } + }; + + int main() { + MyType my{42}; + auto s = std::format(\"{}\", my); + return 0; + } + " + HAS_FORMAT + + ) + set(CMAKE_REQUIRED_FLAGS ${temp_flags}) + if(HAS_FORMAT) + message("-- INFO: Found std::format support") + target_compile_definitions(dpp PUBLIC DPP_HAS_FORMAT) + else () + message("-- INFO: std::format support not found") + endif() +endif () \ No newline at end of file diff --git a/include/dpp/snowflake.h b/include/dpp/snowflake.h index 1142d00459..e55d8b3f2b 100644 --- a/include/dpp/snowflake.h +++ b/include/dpp/snowflake.h @@ -26,19 +26,11 @@ #include #include -#if __cplusplus >= 202002L -//fix for https://github.com/llvm/llvm-project/issues/77773 and -// apple support on clang 14 https://developer.apple.com/xcode/cpp/ -#if (defined(__cpp_lib_format) || \ - (defined(__clang__) && __clang_major__ >= 14 && !defined(__APPLE__) && __has_include())) || ( defined(__GNUC__) && __GNUC__ >= 13) - -#define DPP_HAS_FORMAT - +#ifdef DPP_HAS_FORMAT #include - -#endif #endif + /** * @brief The main namespace for D++ functions. classes and types */ From bc364e12e29156fe3764673429cc73a6bbf71eda Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Fri, 19 Jul 2024 16:06:23 +0200 Subject: [PATCH 15/28] cmake clear --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85f4547080..df8e671d73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ option(RUN_LDCONFIG "Run ldconfig after installation" ON) option(DPP_INSTALL "Generate the install target" ON) option(DPP_BUILD_TEST "Build the test program" ON) option(DPP_NO_VCPKG "No VCPKG" OFF) -option(DPP_CORO "Experimental support for C++20 coroutines" ON) +option(DPP_CORO "Experimental support for C++20 coroutines" OFF) option(DPP_USE_EXTERNAL_JSON "Use an external installation of nlohmann::json" OFF) option(DPP_USE_PCH "Use precompiled headers to speed up compilation" OFF) option(AVX_TYPE "Force AVX type for speeding up audio mixing" OFF) From a07ee9275a70231f2df85c78c7e8b062a140d91a Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Fri, 19 Jul 2024 16:31:52 +0200 Subject: [PATCH 16/28] check for MSVC --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df8e671d73..e10a47b575 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,7 +120,11 @@ if ("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES) include(CheckCXXSourceCompiles) unset(HAS_FORMAT CACHE) set(temp_flags "${CMAKE_REQUIRED_FLAGS}") - set(CMAKE_REQUIRED_FLAGS "-std=c++20") + if (WIN32) + set(CMAKE_REQUIRED_FLAGS "/std:c++20") + else () + set(CMAKE_REQUIRED_FLAGS "-std=c++20") + endif () check_cxx_source_compiles( " #include From 64cce72457b2d6895dc6e2d289e34cafbc034f10 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Fri, 19 Jul 2024 16:32:33 +0200 Subject: [PATCH 17/28] check for MSVC --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e10a47b575..63c00d11e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,7 +120,7 @@ if ("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES) include(CheckCXXSourceCompiles) unset(HAS_FORMAT CACHE) set(temp_flags "${CMAKE_REQUIRED_FLAGS}") - if (WIN32) + if (MSVC) set(CMAKE_REQUIRED_FLAGS "/std:c++20") else () set(CMAKE_REQUIRED_FLAGS "-std=c++20") From ed54d29a7d1ec9a83e7cf0722997cef211e12f5c Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Fri, 19 Jul 2024 16:42:17 +0200 Subject: [PATCH 18/28] fix cmake checks --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 63c00d11e8..095cf108e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,7 +116,7 @@ else() message("-- Using bundled nlohmann::json") endif() -if ("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES) +if (CMAKE_CXX_STANDARD GREATER_EQUAL 20) include(CheckCXXSourceCompiles) unset(HAS_FORMAT CACHE) set(temp_flags "${CMAKE_REQUIRED_FLAGS}") From f5351877c15b992013bfc4b5939c9b67e5d32572 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Fri, 19 Jul 2024 16:53:37 +0200 Subject: [PATCH 19/28] fix version check --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 095cf108e0..5a055d19a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ option(RUN_LDCONFIG "Run ldconfig after installation" ON) option(DPP_INSTALL "Generate the install target" ON) option(DPP_BUILD_TEST "Build the test program" ON) option(DPP_NO_VCPKG "No VCPKG" OFF) -option(DPP_CORO "Experimental support for C++20 coroutines" OFF) +option(DPP_CORO "Experimental support for C++20 coroutines" ON) option(DPP_USE_EXTERNAL_JSON "Use an external installation of nlohmann::json" OFF) option(DPP_USE_PCH "Use precompiled headers to speed up compilation" OFF) option(AVX_TYPE "Force AVX type for speeding up audio mixing" OFF) @@ -116,7 +116,8 @@ else() message("-- Using bundled nlohmann::json") endif() -if (CMAKE_CXX_STANDARD GREATER_EQUAL 20) + +if(CMAKE_CXX_STANDARD EQUAL 20 OR DPP_CORO) include(CheckCXXSourceCompiles) unset(HAS_FORMAT CACHE) set(temp_flags "${CMAKE_REQUIRED_FLAGS}") From c3dd88d749eac4a4b32d4eff56894ffd28a4e9d6 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Fri, 19 Jul 2024 16:56:27 +0200 Subject: [PATCH 20/28] cmake clean --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a055d19a0..6cb5a6e23f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ option(RUN_LDCONFIG "Run ldconfig after installation" ON) option(DPP_INSTALL "Generate the install target" ON) option(DPP_BUILD_TEST "Build the test program" ON) option(DPP_NO_VCPKG "No VCPKG" OFF) -option(DPP_CORO "Experimental support for C++20 coroutines" ON) +option(DPP_CORO "Experimental support for C++20 coroutines" OFF) option(DPP_USE_EXTERNAL_JSON "Use an external installation of nlohmann::json" OFF) option(DPP_USE_PCH "Use precompiled headers to speed up compilation" OFF) option(AVX_TYPE "Force AVX type for speeding up audio mixing" OFF) From 67de1421862f75bb83497778f5bd713fa18a5e42 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Fri, 19 Jul 2024 17:25:08 +0200 Subject: [PATCH 21/28] allow higher version of c++ then c++20 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cb5a6e23f..096220b596 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,7 +117,7 @@ else() endif() -if(CMAKE_CXX_STANDARD EQUAL 20 OR DPP_CORO) +if(CMAKE_CXX_STANDARD GREATER_EQUAL 20 OR DPP_CORO) include(CheckCXXSourceCompiles) unset(HAS_FORMAT CACHE) set(temp_flags "${CMAKE_REQUIRED_FLAGS}") From ba4aff21e5a3b4e59a1b48fdb4f879ce355c6a4a Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Fri, 19 Jul 2024 21:01:41 +0200 Subject: [PATCH 22/28] making requested changes --- CMakeLists.txt | 2 +- include/dpp/snowflake.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 096220b596..d497aba6db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,4 +159,4 @@ if(CMAKE_CXX_STANDARD GREATER_EQUAL 20 OR DPP_CORO) else () message("-- INFO: std::format support not found") endif() -endif () \ No newline at end of file +endif () diff --git a/include/dpp/snowflake.h b/include/dpp/snowflake.h index e55d8b3f2b..7613f95970 100644 --- a/include/dpp/snowflake.h +++ b/include/dpp/snowflake.h @@ -30,7 +30,6 @@ #include #endif - /** * @brief The main namespace for D++ functions. classes and types */ @@ -305,4 +304,4 @@ struct std::formatter return std::format_to(ctx.out(), "{}", snowflake.str()); } }; -#endif //DPP_HAS_FORMAT \ No newline at end of file +#endif //DPP_HAS_FORMAT From 22a37358e2fcdb2f1a23097fc1482ff922f48fa7 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Fri, 19 Jul 2024 21:09:55 +0200 Subject: [PATCH 23/28] making requested changes --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d497aba6db..4ced53cce8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,7 +116,6 @@ else() message("-- Using bundled nlohmann::json") endif() - if(CMAKE_CXX_STANDARD GREATER_EQUAL 20 OR DPP_CORO) include(CheckCXXSourceCompiles) unset(HAS_FORMAT CACHE) From 51f74929fde56ca5ac2d6bb1512c0239200b627e Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Sat, 20 Jul 2024 14:40:56 +0200 Subject: [PATCH 24/28] utilising cmake config file to make defenitions --- .gitignore | 1 + CMakeLists.txt | 8 +++++++- include/dpp/autoconfig.h.in | 25 +++++++++++++++++++++++++ include/dpp/snowflake.h | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 include/dpp/autoconfig.h.in diff --git a/.gitignore b/.gitignore index bbf269173b..20a8eef932 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ buildtools/composer.phar src/build cmake-build-debug docpages/example_code/build +*autoconfig.h # tests test diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ced53cce8..556dd268e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,8 +154,14 @@ if(CMAKE_CXX_STANDARD GREATER_EQUAL 20 OR DPP_CORO) set(CMAKE_REQUIRED_FLAGS ${temp_flags}) if(HAS_FORMAT) message("-- INFO: Found std::format support") - target_compile_definitions(dpp PUBLIC DPP_HAS_FORMAT) + set(DPP_HAS_FORMAT 1) else () message("-- INFO: std::format support not found") endif() endif () + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/include/dpp/autoconfig.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/include/dpp/autoconfig.h + @ONLY +) \ No newline at end of file diff --git a/include/dpp/autoconfig.h.in b/include/dpp/autoconfig.h.in new file mode 100644 index 0000000000..cfb96269a2 --- /dev/null +++ b/include/dpp/autoconfig.h.in @@ -0,0 +1,25 @@ +/************************************************************************************ + * + * D++, A Lightweight C++ library for Discord + * + * SPDX-License-Identifier: Apache-2.0 + * Copyright 2021 Craig Edwards and D++ contributors + * (https://github.com/brainboxdotcc/DPP/graphs/contributors) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ************************************************************************************/ + +#pragma once +#cmakedefine DPP_HAS_FORMAT + diff --git a/include/dpp/snowflake.h b/include/dpp/snowflake.h index 7613f95970..e6679b04d0 100644 --- a/include/dpp/snowflake.h +++ b/include/dpp/snowflake.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include From 25977dc650c2db5f0feb2b78f3489ecde0964a88 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Sun, 21 Jul 2024 17:20:23 +0200 Subject: [PATCH 25/28] fix new line --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 556dd268e9..2a67f21717 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,4 +164,4 @@ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/dpp/autoconfig.h.in ${CMAKE_CURRENT_SOURCE_DIR}/include/dpp/autoconfig.h @ONLY -) \ No newline at end of file +) From c11da4f0b5e98a4b82e5c1307f302789c9ee9577 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Mon, 22 Jul 2024 12:00:22 +0200 Subject: [PATCH 26/28] add addtitional check for c++20 in autoconfig --- include/dpp/autoconfig.h.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/dpp/autoconfig.h.in b/include/dpp/autoconfig.h.in index cfb96269a2..2c35986c21 100644 --- a/include/dpp/autoconfig.h.in +++ b/include/dpp/autoconfig.h.in @@ -21,5 +21,7 @@ ************************************************************************************/ #pragma once -#cmakedefine DPP_HAS_FORMAT +#if __cplusplus >= 202002L +#cmakedefine DPP_HAS_FORMAT +#endif From bc0766aa1758d7538eb00042cee7d53a8a77210f Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Mon, 22 Jul 2024 12:01:09 +0200 Subject: [PATCH 27/28] add addtitional check for c++20 in autoconfig --- include/dpp/autoconfig.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/dpp/autoconfig.h.in b/include/dpp/autoconfig.h.in index 2c35986c21..fd53c66bfe 100644 --- a/include/dpp/autoconfig.h.in +++ b/include/dpp/autoconfig.h.in @@ -22,6 +22,6 @@ #pragma once -#if __cplusplus >= 202002L +#if __cplusplus >= 202002L // c++20 or higher #cmakedefine DPP_HAS_FORMAT #endif From bc01f2f981264446d095c1daad1451947bdc13a9 Mon Sep 17 00:00:00 2001 From: ruslan-ilesik Date: Sun, 4 Aug 2024 13:20:08 +0200 Subject: [PATCH 28/28] removed autconfig and adjusted dpp for formatters without it --- .gitignore | 1 - CMakeLists.txt | 51 +------------------------------------ include/dpp/autoconfig.h.in | 27 -------------------- include/dpp/snowflake.h | 7 +++-- library/CMakeLists.txt | 6 ++++- src/unittest/test.cpp | 4 +-- 6 files changed, 11 insertions(+), 85 deletions(-) delete mode 100644 include/dpp/autoconfig.h.in diff --git a/.gitignore b/.gitignore index 20a8eef932..bbf269173b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,6 @@ buildtools/composer.phar src/build cmake-build-debug docpages/example_code/build -*autoconfig.h # tests test diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a67f21717..f2e7a58f2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ option(DPP_INSTALL "Generate the install target" ON) option(DPP_BUILD_TEST "Build the test program" ON) option(DPP_NO_VCPKG "No VCPKG" OFF) option(DPP_CORO "Experimental support for C++20 coroutines" OFF) +option(DPP_FORMATTERS "Support for C++20 formatters" OFF) option(DPP_USE_EXTERNAL_JSON "Use an external installation of nlohmann::json" OFF) option(DPP_USE_PCH "Use precompiled headers to speed up compilation" OFF) option(AVX_TYPE "Force AVX type for speeding up audio mixing" OFF) @@ -115,53 +116,3 @@ else() # that made no sense, it seems they may have changed their parsing rules somehow. message("-- Using bundled nlohmann::json") endif() - -if(CMAKE_CXX_STANDARD GREATER_EQUAL 20 OR DPP_CORO) - include(CheckCXXSourceCompiles) - unset(HAS_FORMAT CACHE) - set(temp_flags "${CMAKE_REQUIRED_FLAGS}") - if (MSVC) - set(CMAKE_REQUIRED_FLAGS "/std:c++20") - else () - set(CMAKE_REQUIRED_FLAGS "-std=c++20") - endif () - check_cxx_source_compiles( - " - #include - #include - - struct MyType { - int value; - std::string str() const { return std::to_string(value); } - }; - - template <> - struct std::formatter : std::formatter { - auto format(const MyType& item, std::format_context& ctx) const -> decltype(ctx.out()) { - return std::format_to(ctx.out(), \"{}\", item.str()); - } - }; - - int main() { - MyType my{42}; - auto s = std::format(\"{}\", my); - return 0; - } - " - HAS_FORMAT - - ) - set(CMAKE_REQUIRED_FLAGS ${temp_flags}) - if(HAS_FORMAT) - message("-- INFO: Found std::format support") - set(DPP_HAS_FORMAT 1) - else () - message("-- INFO: std::format support not found") - endif() -endif () - -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/include/dpp/autoconfig.h.in - ${CMAKE_CURRENT_SOURCE_DIR}/include/dpp/autoconfig.h - @ONLY -) diff --git a/include/dpp/autoconfig.h.in b/include/dpp/autoconfig.h.in deleted file mode 100644 index fd53c66bfe..0000000000 --- a/include/dpp/autoconfig.h.in +++ /dev/null @@ -1,27 +0,0 @@ -/************************************************************************************ - * - * D++, A Lightweight C++ library for Discord - * - * SPDX-License-Identifier: Apache-2.0 - * Copyright 2021 Craig Edwards and D++ contributors - * (https://github.com/brainboxdotcc/DPP/graphs/contributors) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ************************************************************************************/ - -#pragma once - -#if __cplusplus >= 202002L // c++20 or higher -#cmakedefine DPP_HAS_FORMAT -#endif diff --git a/include/dpp/snowflake.h b/include/dpp/snowflake.h index e6679b04d0..109f16a53a 100644 --- a/include/dpp/snowflake.h +++ b/include/dpp/snowflake.h @@ -23,11 +23,10 @@ #include #include #include -#include #include #include -#ifdef DPP_HAS_FORMAT +#ifdef DPP_FORMATTERS #include #endif @@ -287,7 +286,7 @@ struct std::hash } }; -#ifdef DPP_HAS_FORMAT +#ifdef DPP_FORMATTERS /* * @brief implementation of formater for dpp::snowflake for std::format support * https://en.cppreference.com/w/cpp/utility/format/formatter @@ -305,4 +304,4 @@ struct std::formatter return std::format_to(ctx.out(), "{}", snowflake.str()); } }; -#endif //DPP_HAS_FORMAT +#endif //DPP_FORMATTERS diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index e0eac6632c..00b2a8b651 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -341,6 +341,10 @@ if(DPP_CORO) COMMAND php buildtools/make_struct.php "\\Dpp\\Generator\\CoroGenerator") endif() +if(DPP_FORMATTERS) + target_compile_definitions(dpp PUBLIC DPP_FORMATTERS) +endif() + if (DPP_BUILD_TEST) enable_testing(${CMAKE_CURRENT_SOURCE_DIR}/..) file(GLOB testnamelist "${CMAKE_CURRENT_SOURCE_DIR}/../src/*") @@ -351,7 +355,7 @@ if (DPP_BUILD_TEST) set (testsrc "") file(GLOB testsrc "${modules_dir}/${testname}/*.cpp") add_executable(${testname} ${testsrc}) - if (DPP_CORO) + if (DPP_CORO OR DPP_FORMATTERS) target_compile_features(${testname} PRIVATE cxx_std_20) else() target_compile_features(${testname} PRIVATE cxx_std_17) diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index 33dddc3d1c..1af1301003 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -381,7 +381,7 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b { // test snowflake: std::format support - #ifdef DPP_HAS_FORMAT + #ifdef DPP_FORMATTERS set_test(SNOWFLAKE_STD_FORMAT, std::format("{}",dpp::snowflake{}) == "0" && std::format("{}",dpp::snowflake{12345}) == "12345" && @@ -389,7 +389,7 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b ); #else set_status(SNOWFLAKE_STD_FORMAT,ts_skipped); - #endif // DPP_HAS_FORMAT + #endif // DPP_FORMATTERS }; { // test dpp::json_interface