From 0ee3974d1f49d8cbcab59ad6565b0229e413b57d Mon Sep 17 00:00:00 2001 From: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com> Date: Mon, 20 Feb 2023 04:12:12 -0600 Subject: [PATCH] refactor: implement c++23 inspired ToUnderlying (#5210) ## Issue being fixed or feature implemented Avoid lots of static_cast's from enums to underlying types. Communicate intention better ## What was done? implement c++23 inspired ToUnderlying, then see std::to_underlying and https://en.cppreference.com/w/cpp/types/underlying_type; Then, we use this instead of static_casts for enums -> underlying type ## How Has This Been Tested? make check ## Breaking Changes None ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation **For repository code-owners and collaborators only** - [x] I have assigned this pull request to a milestone --------- Co-authored-by: Konstantin Akimov --- src/Makefile.am | 1 + src/evo/providertx.cpp | 5 ++- src/evo/providertx.h | 5 ++- src/evo/simplifiedmns.cpp | 5 ++- src/llmq/blockprocessor.cpp | 31 ++++++++-------- src/llmq/commitment.cpp | 5 ++- src/llmq/commitment.h | 3 +- src/llmq/debug.cpp | 7 ++-- src/llmq/debug.h | 4 +- src/llmq/dkgsession.cpp | 11 +++--- src/llmq/dkgsession.h | 3 +- src/llmq/dkgsessionhandler.cpp | 49 ++++++++++++++++++------- src/llmq/dkgsessionhandler.h | 19 +--------- src/llmq/dkgsessionmgr.cpp | 7 ++-- src/llmq/quorums.cpp | 25 +++++++------ src/llmq/signing.cpp | 3 +- src/llmq/signing_shares.cpp | 5 ++- src/llmq/utils.cpp | 5 ++- src/qt/optionsdialog.cpp | 3 +- src/qt/rpcconsole.cpp | 7 ++-- src/test/llmq_dkg_tests.cpp | 3 +- src/util/underlying.h | 14 +++++++ test/lint/lint-circular-dependencies.sh | 2 + 23 files changed, 131 insertions(+), 91 deletions(-) create mode 100644 src/util/underlying.h diff --git a/src/Makefile.am b/src/Makefile.am index 7ac685cffc..af0ce5848b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -310,6 +310,7 @@ BITCOIN_CORE_H = \ util/message.h \ util/moneystr.h \ util/ranges.h \ + util/underlying.h \ util/serfloat.h \ util/settings.h \ util/sock.h \ diff --git a/src/evo/providertx.cpp b/src/evo/providertx.cpp index 865dd0d527..26123cb63e 100644 --- a/src/evo/providertx.cpp +++ b/src/evo/providertx.cpp @@ -9,6 +9,7 @@ #include #include #include