From 2cffe55ee1783f51bc0489213694812885b92ef7 Mon Sep 17 00:00:00 2001 From: mutouyun Date: Sat, 13 Jan 2024 16:20:06 +0800 Subject: [PATCH] Update constants to use static constexpr --- include/libconcur/concurrent.h | 6 ++--- include/libimp/countof.h | 10 ++++---- include/libimp/dataof.h | 16 ++++++------- include/libimp/log.h | 2 +- include/libimp/result.h | 28 +++++++++++----------- include/libpmr/block_pool.h | 4 ++-- include/libpmr/small_storage.h | 2 +- src/libimp/fmt.cpp | 2 +- test/concur/test_concur_circular_queue.cpp | 2 +- test/concur/test_concur_concurrent.cpp | 4 ++-- 10 files changed, 38 insertions(+), 38 deletions(-) diff --git a/include/libconcur/concurrent.h b/include/libconcur/concurrent.h index 440d664..33d8692 100644 --- a/include/libconcur/concurrent.h +++ b/include/libconcur/concurrent.h @@ -379,15 +379,15 @@ struct producer { private: friend struct producer::header_impl; - constexpr static index_t get_index(state::flag_t flags) noexcept { + static constexpr index_t get_index(state::flag_t flags) noexcept { return index_t(flags); } - constexpr static index_t get_begin(state::flag_t flags) noexcept { + static constexpr index_t get_begin(state::flag_t flags) noexcept { return index_t(flags >> (sizeof(index_t) * CHAR_BIT)); } - constexpr static state::flag_t make_flags(index_t idx, index_t beg) noexcept { + static constexpr state::flag_t make_flags(index_t idx, index_t beg) noexcept { return state::flag_t(idx) | (state::flag_t(beg) << (sizeof(index_t) * CHAR_BIT)); } }; diff --git a/include/libimp/countof.h b/include/libimp/countof.h index 72df251..b35a95c 100644 --- a/include/libimp/countof.h +++ b/include/libimp/countof.h @@ -29,7 +29,7 @@ private: static std::false_type check(...); public: using type = decltype(check(nullptr)); - constexpr static auto value = type::value; + static constexpr auto value = type::value; }; template @@ -41,7 +41,7 @@ private: static std::false_type check(...); public: using type = decltype(check(nullptr)); - constexpr static auto value = type::value; + static constexpr auto value = type::value; }; template ::value @@ -50,21 +50,21 @@ struct trait; template struct trait { - constexpr static auto countof(T const (&)[N]) noexcept { + static constexpr auto countof(T const (&)[N]) noexcept { return N; } }; template struct trait { - constexpr static auto countof(C const &c) noexcept(noexcept(c.size())) { + static constexpr auto countof(C const &c) noexcept(noexcept(c.size())) { return c.size(); } }; template struct trait { - constexpr static auto countof(C const &c) noexcept(noexcept(c.Size())) { + static constexpr auto countof(C const &c) noexcept(noexcept(c.Size())) { return c.Size(); } }; diff --git a/include/libimp/dataof.h b/include/libimp/dataof.h index de19f62..baddd06 100644 --- a/include/libimp/dataof.h +++ b/include/libimp/dataof.h @@ -29,7 +29,7 @@ private: static std::false_type check(...); public: using type = decltype(check(nullptr)); - constexpr static auto value = type::value; + static constexpr auto value = type::value; }; template @@ -41,7 +41,7 @@ private: static std::false_type check(...); public: using type = decltype(check(nullptr)); - constexpr static auto value = type::value; + static constexpr auto value = type::value; }; template ::value @@ -50,10 +50,10 @@ struct trait; template struct trait { - constexpr static T const *dataof(T const (&arr)[N]) noexcept { + static constexpr T const *dataof(T const (&arr)[N]) noexcept { return arr; } - constexpr static T *dataof(T (&arr)[N]) noexcept { + static constexpr T *dataof(T (&arr)[N]) noexcept { return arr; } }; @@ -61,7 +61,7 @@ struct trait { template struct trait { template - constexpr static auto dataof(T &&c) noexcept(noexcept(c.data())) { + static constexpr auto dataof(T &&c) noexcept(noexcept(c.data())) { return std::forward(c).data(); } }; @@ -69,7 +69,7 @@ struct trait { template struct trait { template - constexpr static auto dataof(T &&c) noexcept(noexcept(c.Data())) { + static constexpr auto dataof(T &&c) noexcept(noexcept(c.Data())) { return std::forward(c).Data(); } }; @@ -77,11 +77,11 @@ struct trait { template struct trait { template - constexpr static T const *dataof(std::initializer_list il) noexcept { + static constexpr T const *dataof(std::initializer_list il) noexcept { return il.begin(); } template - constexpr static T const *dataof(T const *p) noexcept { + static constexpr T const *dataof(T const *p) noexcept { return p; } }; diff --git a/include/libimp/log.h b/include/libimp/log.h index 01c8edc..acbf6eb 100644 --- a/include/libimp/log.h +++ b/include/libimp/log.h @@ -54,7 +54,7 @@ bool unfold_tuple_fmt_to(fmt_context &ctx, Tp const &tp, std::index_sequence bool context_to_string(fmt_context &f_ctx, context const &l_ctx) noexcept { - constexpr static char types[] = { + static constexpr char types[] = { 'T', 'D', 'I', 'W', 'E', 'F', }; LIBIMP_TRY { diff --git a/include/libimp/result.h b/include/libimp/result.h index f74f450..6b9d374 100644 --- a/include/libimp/result.h +++ b/include/libimp/result.h @@ -41,27 +41,27 @@ struct generic_traits { using storage_t = std::tuple; /// \brief Custom initialization. - constexpr static void init_code(storage_t &code) noexcept { + static constexpr void init_code(storage_t &code) noexcept { code = {{}, std::error_code(-1, std::generic_category())}; } - constexpr static void init_code(storage_t &code, T value, std::error_code const &ec) noexcept { + static constexpr void init_code(storage_t &code, T value, std::error_code const &ec) noexcept { code = {value, ec}; } - constexpr static void init_code(storage_t &code, T value) noexcept { + static constexpr void init_code(storage_t &code, T value) noexcept { code = {value, {}}; } - constexpr static void init_code(storage_t &code, std::error_code const &ec) noexcept { + static constexpr void init_code(storage_t &code, std::error_code const &ec) noexcept { code = {{}, ec}; } /// \brief Custom type data acquisition. - constexpr static T get_value(storage_t const &code) noexcept { + static constexpr T get_value(storage_t const &code) noexcept { return std::get<0>(code); } - constexpr static bool get_ok(storage_t const &code) noexcept { + static constexpr bool get_ok(storage_t const &code) noexcept { return !std::get<1>(code); } - constexpr static std::error_code get_error(storage_t const &code) noexcept { + static constexpr std::error_code get_error(storage_t const &code) noexcept { return std::get<1>(code); } }; @@ -72,18 +72,18 @@ struct default_traits { using storage_t = std::error_code; /// \brief Custom initialization. - constexpr static void init_code(storage_t &code) noexcept { + static constexpr void init_code(storage_t &code) noexcept { code = std::error_code(-1, std::generic_category()); } - constexpr static void init_code(storage_t &code, std::error_code const &ec) noexcept { + static constexpr void init_code(storage_t &code, std::error_code const &ec) noexcept { code = ec; } /// \brief Custom type data acquisition. - constexpr static bool get_ok(storage_t const &code) noexcept { + static constexpr bool get_ok(storage_t const &code) noexcept { return !code; } - constexpr static std::error_code get_error(storage_t const &code) noexcept { + static constexpr std::error_code get_error(storage_t const &code) noexcept { return code; } @@ -94,7 +94,7 @@ struct default_traits { template struct default_traits::value>> : generic_traits { /// \brief Custom initialization. - constexpr static void init_code(typename generic_traits::storage_t &code, + static constexpr void init_code(typename generic_traits::storage_t &code, T value, bool ok) noexcept { code = {value, ok ? std::error_code() : std::error_code(-1, std::generic_category())}; } @@ -107,11 +107,11 @@ struct default_traits::value>> : generic template struct default_traits::value>> : generic_traits { /// \brief Custom initialization. - constexpr static void init_code(typename generic_traits::storage_t &code, + static constexpr void init_code(typename generic_traits::storage_t &code, std::nullptr_t, std::error_code const &ec) noexcept { code = {nullptr, ec}; } - constexpr static void init_code(typename generic_traits::storage_t &code, + static constexpr void init_code(typename generic_traits::storage_t &code, std::nullptr_t) noexcept { code = {nullptr, std::error_code(-1, std::generic_category())}; } diff --git a/include/libpmr/block_pool.h b/include/libpmr/block_pool.h index 7649634..7fc1141 100644 --- a/include/libpmr/block_pool.h +++ b/include/libpmr/block_pool.h @@ -163,7 +163,7 @@ class block_pool<0, 0> { using central_cache_pool_t = central_cache_pool; public: - constexpr static std::size_t block_size = 0; + static constexpr std::size_t block_size = 0; block_pool() noexcept : cursor_(central_cache_pool_t::instance().aqueire()) {} ~block_pool() noexcept { @@ -202,7 +202,7 @@ class block_pool { } public: - constexpr static std::size_t block_size = BlockSize; + static constexpr std::size_t block_size = BlockSize; block_pool() noexcept : cursor_(expand()) {} ~block_pool() noexcept { diff --git a/include/libpmr/small_storage.h b/include/libpmr/small_storage.h index 58d6792..aee998d 100644 --- a/include/libpmr/small_storage.h +++ b/include/libpmr/small_storage.h @@ -494,7 +494,7 @@ public: template class small_storage { - constexpr static std::size_t storage_size = sizeof(holder) - sizeof(void *) + N; + static constexpr std::size_t storage_size = sizeof(holder) - sizeof(void *) + N; static_assert(storage_size >= sizeof(holder), "N is not large enough to hold a pointer."); alignas(std::max_align_t) std::array<::LIBIMP::byte, storage_size> storage_; diff --git a/src/libimp/fmt.cpp b/src/libimp/fmt.cpp index 94bb284..ac17e92 100644 --- a/src/libimp/fmt.cpp +++ b/src/libimp/fmt.cpp @@ -21,7 +21,7 @@ LIBIMP_NAMESPACE_BEG_ namespace { struct sfmt_policy { - constexpr static std::size_t aligned_size = 32U; + static constexpr std::size_t aligned_size = 32U; }; template diff --git a/test/concur/test_concur_circular_queue.cpp b/test/concur/test_concur_circular_queue.cpp index 018b79c..54fc1c8 100644 --- a/test/concur/test_concur_circular_queue.cpp +++ b/test/concur/test_concur_circular_queue.cpp @@ -93,7 +93,7 @@ void test_queue(std::size_t np, std::size_t nc) { }; circular_queue que; - constexpr static std::uint32_t loop_size = 10'0000; + static constexpr std::uint32_t loop_size = 10'0000; std::atomic sum {0}; std::atomic running {np}; diff --git a/test/concur/test_concur_concurrent.cpp b/test/concur/test_concur_concurrent.cpp index b521a27..f8e1837 100644 --- a/test/concur/test_concur_concurrent.cpp +++ b/test/concur/test_concur_concurrent.cpp @@ -95,7 +95,7 @@ void test_unicast(std::size_t np, std::size_t nc) { LIBIMP_LOG_(); log.info("\n\tStart with: ", imp::nameof(), ", ", np, " producers, ", nc, " consumers..."); - constexpr static std::uint32_t loop_size = 100'0000; + static constexpr std::uint32_t loop_size = 100'0000; concur::element circ[32] {}; PC pc; @@ -232,7 +232,7 @@ void test_broadcast(std::size_t np, std::size_t nc) { typename concur::traits::header hdr {imp::make_span(circ)}; ASSERT_TRUE(hdr.valid()); - constexpr static std::uint32_t loop_size = 10'0000; + static constexpr std::uint32_t loop_size = 10'0000; std::atomic sum {0}; std::atomic running {np};