mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-17 11:45:50 +00:00
Import Sprout. This is to fix the build on clang.
Sprout is needed because pow, log2 and log10 are constexpr on gcc, but that's nonstandard. Sprout provides the constexpr version of those functions. Also fix warnings. I still get plenty of warnings about some suggested paretheses, but it seems to be a bug from clang. See https://llvm.org/bugs/show_bug.cgi?id=21629 for the bug report.
This commit is contained in:
parent
d46cb322b9
commit
417e7105d3
5 changed files with 20 additions and 8 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -7,3 +7,6 @@
|
|||
[submodule "lib/better-enums"]
|
||||
path = lib/better-enums
|
||||
url = https://github.com/aantron/better-enums
|
||||
[submodule "lib/sprout"]
|
||||
path = lib/sprout
|
||||
url = https://github.com/bolero-MURAKAMI/Sprout.git
|
||||
|
|
|
@ -106,6 +106,7 @@ target_compile_features(${PROJECT_NAME}
|
|||
target_include_directories(${bare_name}-inc
|
||||
INTERFACE ${PROJECT_BINARY_DIR}
|
||||
INTERFACE ${CMAKE_SOURCE_DIR}/include
|
||||
INTERFACE ${CMAKE_SOURCE_DIR}/lib/sprout
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -21,10 +21,12 @@
|
|||
#include "compatibility.h"
|
||||
#include "helpers/sequence_bt.hpp"
|
||||
#include "helpers/MaxSizedArray.hpp"
|
||||
#include "sprout/math/log10.hpp"
|
||||
#include "sprout/math/log2.hpp"
|
||||
#include "sprout/math/pow.hpp"
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <limits>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
@ -112,7 +114,7 @@ namespace dinhelp {
|
|||
static std::size_t count_digits ( T parValue ) a_pure;
|
||||
static typename std::make_unsigned<T>::type make_unsigned ( T parValue ) a_pure;
|
||||
static constexpr std::size_t count_digits_bt (std::size_t parNum) {
|
||||
return (parNum == 0 ? 0 : static_cast<std::size_t>(std::log10(static_cast<double>(parNum)) / std::log10(static_cast<double>(base)))) + 1;
|
||||
return (parNum == 0 ? 0 : static_cast<std::size_t>(sprout::log10(static_cast<double>(parNum)) / sprout::log10(static_cast<double>(base)))) + 1;
|
||||
}
|
||||
};
|
||||
} //namespace implem
|
||||
|
@ -133,7 +135,7 @@ namespace dinhelp {
|
|||
|
||||
static typename std::make_unsigned<T>::type make_unsigned ( T parValue ) a_pure;
|
||||
static constexpr std::size_t count_digits_bt (std::size_t parNum) {
|
||||
return (parNum == 0 ? 0 : static_cast<std::size_t>(std::log10(static_cast<double>(parNum)))) + 1 + (std::numeric_limits<T>::is_signed ? 1 : 0);
|
||||
return (parNum == 0 ? 0 : static_cast<std::size_t>(sprout::log10(static_cast<double>(parNum)))) + 1 + (std::numeric_limits<T>::is_signed ? 1 : 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -153,7 +155,7 @@ namespace dinhelp {
|
|||
static std::size_t count_digits ( T parValue ) a_pure;
|
||||
static typename std::make_unsigned<T>::type make_unsigned ( T parValue ) a_pure;
|
||||
static constexpr std::size_t count_digits_bt (std::size_t parNum) {
|
||||
return (parNum == 0 ? 0 : static_cast<std::size_t>(std::log2(static_cast<double>(parNum)))) + 1;
|
||||
return (parNum == 0 ? 0 : static_cast<std::size_t>(sprout::log2(static_cast<double>(parNum)))) + 1;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -163,7 +165,7 @@ namespace dinhelp {
|
|||
std::size_t dec<T>::count_digits_implem (T parValue, dinhelp::bt::index_seq<Powers...>, dinhelp::bt::index_seq<Digits...>) {
|
||||
typedef typename std::make_unsigned<T>::type UT;
|
||||
static constexpr UT powers[] = { 0, static_cast<UT>(dinhelp::implem::power<10, Powers + 1>::value)... };
|
||||
static constexpr std::size_t maxdigits[] = { count_digits_bt(static_cast<std::size_t>(::pow(2.0, Digits))) - (std::numeric_limits<T>::is_signed ? 1 : 0)... };
|
||||
static constexpr std::size_t maxdigits[] = { count_digits_bt(static_cast<std::size_t>(sprout::pow(2.0, Digits))) - (std::numeric_limits<T>::is_signed ? 1 : 0)... };
|
||||
const auto bits = sizeof(parValue) * CHAR_BIT - dinhelp::implem::count_leading_zeroes<T>(dinhelp::implem::abs(parValue));
|
||||
static_assert(std::is_same<UT, decltype(dinhelp::implem::abs(parValue))>::value, "Unexpected type");
|
||||
return (dinhelp::implem::abs(parValue) < powers[maxdigits[bits] - 1] ? maxdigits[bits] - 1 : maxdigits[bits]) + dinhelp::implem::is_negative<T>::check(parValue);
|
||||
|
|
1
lib/sprout
Submodule
1
lib/sprout
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit fea5e752bda763c27ecd6f84531cdd0b4f82399d
|
|
@ -36,13 +36,18 @@ namespace redis {
|
|||
ev_break(parLoop, EVBREAK_ALL);
|
||||
}
|
||||
|
||||
void lock_mutex_libev (ev_loop* parLoop) {
|
||||
void lock_mutex_libev (ev_loop* parLoop) noexcept {
|
||||
std::mutex* mtx = static_cast<std::mutex*>(ev_userdata(parLoop));
|
||||
assert(mtx);
|
||||
mtx->lock();
|
||||
try {
|
||||
mtx->lock();
|
||||
}
|
||||
catch (const std::system_error&) {
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
void unlock_mutex_libev (ev_loop* parLoop) {
|
||||
void unlock_mutex_libev (ev_loop* parLoop) noexcept {
|
||||
std::mutex* mtx = static_cast<std::mutex*>(ev_userdata(parLoop));
|
||||
assert(mtx);
|
||||
mtx->unlock();
|
||||
|
|
Loading…
Add table
Reference in a new issue