33
44#include < cstddef>
55#include < cstdint>
6- #include < cmath>
76#include < type_traits>
87#include < utility>
98#include < new>
@@ -47,6 +46,17 @@ namespace details {
4746 Bits <= 16 , std::uint_least16_t , std::conditional_t <
4847 Bits <= 32 , std::uint_least32_t , std::conditional_t <
4948 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+ }
5060}
5161
5262// / Simple default deleter
@@ -115,9 +125,8 @@ struct policy_queries {
115125 " enable_observer_from_this() must take a control block in its constructor if the "
116126 " policy is sealed and requires support for observer_from_this() in constructors." );
117127
128+ using policy = Policy;
118129 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;
121130
122131 static constexpr bool eoft_base_is_virtual () noexcept {
123132 return Policy::allow_eoft_multiple_inheritance &&
@@ -144,8 +153,10 @@ struct policy_queries {
144153
145154template <typename Policy>
146155struct 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;
149160};
150161
151162namespace details {
0 commit comments