3
3
4
4
#include < cstddef>
5
5
#include < cstdint>
6
- #include < cmath>
7
6
#include < type_traits>
8
7
#include < utility>
9
8
#include < new>
@@ -47,6 +46,17 @@ namespace details {
47
46
Bits <= 16 , std::uint_least16_t , std::conditional_t <
48
47
Bits <= 32 , std::uint_least32_t , std::conditional_t <
49
48
Bits <= 64 , std::uint_least64_t , std::size_t >>>> {};
49
+
50
+ // courtesy of https://stackoverflow.com/a/23782939
51
+ constexpr std::size_t floor_log2 (std::size_t x)
52
+ {
53
+ return x == 1 ? 0 : 1 +floor_log2 (x >> 1 );
54
+ }
55
+
56
+ constexpr std::size_t ceil_log2 (std::size_t x)
57
+ {
58
+ return x == 1 ? 0 : floor_log2 (x - 1 ) + 1 ;
59
+ }
50
60
}
51
61
52
62
// / Simple default deleter
@@ -115,9 +125,8 @@ struct policy_queries {
115
125
" enable_observer_from_this() must take a control block in its constructor if the "
116
126
" policy is sealed and requires support for observer_from_this() in constructors." );
117
127
128
+ using policy = Policy;
118
129
using observer_policy = typename Policy::observer_policy;
119
- using control_block_storage_type = typename details::unsigned_least<
120
- static_cast <std::size_t >(std::ceil(std::log2(observer_policy::max_observers)))>::type;
121
130
122
131
static constexpr bool eoft_base_is_virtual () noexcept {
123
132
return Policy::allow_eoft_multiple_inheritance &&
@@ -144,8 +153,10 @@ struct policy_queries {
144
153
145
154
template <typename Policy>
146
155
struct observer_policy_queries {
147
- using control_block_storage_type = typename details::unsigned_least<1 +
148
- static_cast <std::size_t >(std::ceil(std::log2(Policy::max_observers)))>::type;
156
+ using observer_policy = Policy;
157
+
158
+ using control_block_storage_type = typename details::unsigned_least<
159
+ 1 + details::ceil_log2(observer_policy::max_observers)>::type;
149
160
};
150
161
151
162
namespace details {
0 commit comments