47template <
typename T,
typename U>
66#if 0 and KBLIB_USE_CXX17
74template <
typename T, std::
size_t N>
83template <
typename T, std::
size_t N>
104 return equal(
a.begin(),
a.end(), b.begin());
133 static_assert(std::is_unsigned<U>::value,
"U must be unsigned");
139 state = {b,
static_cast<U
>(
a + b)};
155template <typename U, std::size_t N = calc_fib_size<U>() + 1>
158 implies<(N > calc_fib_size<U>()), std::is_unsigned<U>::value>::value,
159 "signed U with large N would trigger signed overflow");
163 for (std::size_t i = 2; i < N; ++i) {
164 ret[i] = ret[i - 1] + ret[i - 2];
176template <
typename U = std::u
intmax_t>
178 constexpr auto arr = make_fib_arr<U>();
179 assert(n >= 0 and
static_cast<std::size_t
>(n) < arr.size());
183inline namespace nums {
195 template <
typename T,
196 std::enable_if_t<std::numeric_limits<T>::is_specialized,
198 constexpr operator T() const
199 noexcept(noexcept(
std::numeric_limits<T>::
max())) {
202 template <
typename T>
204 noexcept(
std::numeric_limits<T>::
max())) {
211 template <
typename L,
typename R>
214 return std::less<>{}(lhs, rhs) ? std::forward<R>(rhs)
215 : std::forward<L>(lhs);
243 template <
typename T>
247 template <
typename T>
251 template <
typename T>
255 template <
typename T>
260 template <
typename T>
264 template <
typename T>
268 template <
typename T>
272 template <
typename T>
277 template <
typename T>
281 template <
typename T>
285 template <
typename T>
289 template <
typename T>
307 template <typename T, enable_if_t<std::numeric_limits<T>::is_specialized,
309 constexpr operator T() const
310 noexcept(noexcept(
std::numeric_limits<T>::
min())) {
313 template <
typename T>
315 noexcept(
std::numeric_limits<T>::
min())) {
322 template <
typename L,
typename R>
325 return std::less<>{}(lhs, rhs) ? std::forward<R>(lhs)
326 : std::forward<L>(rhs);
329 template <
typename T>
333 template <
typename T>
337 template <
typename T>
341 template <
typename T>
346 template <
typename T>
350 template <
typename T>
354 template <
typename T>
358 template <
typename T>
363 template <
typename T>
367 template <
typename T>
371 template <
typename T>
375 template <
typename T>
459template <
typename T =
double>
461 return 3.1415926535897932384626433832795028841971693993751l;
463template <
typename T =
double>
467template <
typename T =
double>
469 return 2.7182818284590452353602874713526624977572470937000l;
471template <
typename T =
double>
473 return 1.4142135623730950488016887242096980785696718753769l;
475template <
typename T =
double>
477 return 1.6180339887498948482045868343656381177203091798058l;
481template <
typename A,
typename F>
484 and std::is_unsigned<A>::value,
491 return static_cast<A
>(x);
496template <
typename A,
typename F>
498 -> enable_if_t<std::is_integral<A>::value and std::is_integral<F>::value
499 and std::is_signed<A>::value
500 and std::is_signed<F>::value,
511template <
typename A,
typename F>
513 -> enable_if_t<std::is_integral<A>::value and std::is_integral<F>::value
514 and std::is_signed<A>::value
515 and std::is_unsigned<F>::value,
536template <
typename T,
typename F>
539 static_assert(std::is_unsigned<T>::value,
"Destination must be unsigned.");
540 return static_cast<T
>((val - low) *
static_cast<T
>(
max) * delta);
552template <
typename T,
typename F>
555 static_assert(std::is_unsigned<T>::value,
"Destination must be unsigned.");
556 auto delta = (high - low) /
static_cast<T
>(
max);
557 return static_cast<T
>((val - low) *
static_cast<T
>(
max) * delta);
This header provides some features of C++17 <type_traits> and other headers for C++14,...
Provides basic compile-time logic operations.
constexpr struct kblib::nums::min_t min
constexpr struct kblib::nums::max_t max
constexpr auto quantize_step(F low, F delta, F val) noexcept -> T
Quantize a real-valued value into a discrete integer.
constexpr auto a(const std::initializer_list< T > &a) -> auto
Index an array literal without naming its type.
constexpr auto fibonacci(int n) noexcept -> U
Compile-time table fibonacci function.
constexpr auto root_2() -> T
typename std::enable_if< B, T >::type enable_if_t
constexpr auto calc_fib_size() noexcept -> std::size_t
Calculate the index of the largest fibonacci number that can be represented by a given unsigned integ...
constexpr auto phi() -> T
constexpr auto make_fib_arr() noexcept -> trivial_array< U, N >
Generates the first N values of the fibonacci sequence.
constexpr auto tau() -> T
constexpr auto quantize_range(F low, F high, F val) noexcept -> T
Quantize a real-valued value into a discrete integer.
constexpr auto saturating_cast(F x) noexcept -> enable_if_t< std::is_integral< A >::value and std::is_integral< F >::value and std::is_unsigned< A >::value, A >
constexpr auto div(T num, U den) noexcept -> decltype(std::div(num, den))
constexpr auto to_unsigned(I x) -> std::make_unsigned_t< I >
Cast integral argument to corresponding unsigned type.
constexpr auto equal(InputIt1 first1, InputIt1 last1, InputIt2 first2) -> bool
A metafunction for logical implication. That is, if A, then B. If not A, B is unimportant.
Shorthand for std::numeric_limits::max().
constexpr friend auto operator>=(max_t, T t) -> bool
constexpr friend auto operator!=(T t, max_t) -> bool
constexpr friend auto operator==(T t, max_t) -> bool
constexpr friend auto operator>(max_t, T t) -> bool
static constexpr auto of() noexcept(noexcept(std::numeric_limits< T >::max()))
constexpr friend auto operator>(T t, max_t) -> bool
constexpr friend auto operator<(T t, max_t) -> bool
constexpr friend auto operator>=(T t, max_t) -> bool
constexpr friend auto operator==(max_t, T t) -> bool
constexpr auto operator()(L &&lhs, R &&rhs) const noexcept -> decltype(auto)
Return the larger of two values. Returns lhs if equal.
constexpr friend auto operator<=(T t, max_t) -> bool
constexpr friend auto operator!=(max_t, T t) -> bool
constexpr friend auto operator<(max_t, max_t) -> std::false_type
constexpr friend auto operator!=(max_t, max_t) -> std::false_type
constexpr friend auto operator<=(max_t, max_t) -> std::true_type
constexpr friend auto operator>=(max_t, max_t) -> std::true_type
constexpr friend auto operator>(max_t, max_t) -> std::false_type
constexpr friend auto operator==(max_t, max_t) -> std::true_type
constexpr friend auto operator<(max_t, T t) -> bool
constexpr friend auto operator<=(max_t, T t) -> bool
Shorthand for std::numeric_limits::min()
constexpr friend auto operator<=(min_t, min_t) -> std::true_type
constexpr friend auto operator>(T t, min_t) -> bool
constexpr friend auto operator>=(T t, min_t) -> bool
constexpr friend auto operator>(max_t, min_t) -> std::true_type
constexpr friend auto operator!=(min_t, min_t) -> std::false_type
constexpr friend auto operator<=(T t, min_t) -> bool
constexpr friend auto operator>(min_t, T t) -> bool
constexpr friend auto operator==(min_t, max_t) -> std::false_type
constexpr friend auto operator<(min_t, max_t) -> std::true_type
constexpr friend auto operator>=(max_t, min_t) -> std::true_type
constexpr friend auto operator==(T t, min_t) -> bool
constexpr friend auto operator<(min_t, min_t) -> std::false_type
constexpr friend auto operator==(max_t, min_t) -> std::false_type
constexpr friend auto operator<(min_t, T t) -> bool
constexpr friend auto operator>=(min_t, max_t) -> std::false_type
constexpr friend auto operator>(min_t, max_t) -> std::false_type
constexpr friend auto operator<(T t, min_t) -> bool
constexpr friend auto operator==(min_t, T t) -> bool
constexpr friend auto operator!=(min_t, T t) -> bool
static constexpr auto of() noexcept(noexcept(std::numeric_limits< T >::min()))
constexpr friend auto operator>(min_t, min_t) -> std::false_type
constexpr auto operator()(L &&lhs, R &&rhs) const noexcept -> decltype(auto)
Returns the smaller of two values. Returns rhs if equal.
constexpr friend auto operator!=(T t, min_t) -> bool
constexpr friend auto operator<=(min_t, max_t) -> std::true_type
constexpr friend auto operator==(min_t, min_t) -> std::true_type
constexpr friend auto operator>=(min_t, T t) -> bool
constexpr friend auto operator!=(max_t, min_t) -> std::true_type
constexpr friend auto operator<=(max_t, min_t) -> std::false_type
constexpr friend auto operator!=(min_t, max_t) -> std::true_type
constexpr friend auto operator<=(min_t, T t) -> bool
constexpr friend auto operator<(max_t, min_t) -> std::false_type
constexpr friend auto operator>=(min_t, min_t) -> std::true_type
std::array isn't constexpr enough in C++14, so a dedicated array class is needed for constexpr functi...
constexpr auto size() const -> std::size_t
constexpr auto begin() const &noexcept -> const T *
constexpr auto begin() &noexcept -> T *
constexpr auto end() const &noexcept -> const T *
constexpr auto operator[](std::size_t n) -> T &
constexpr auto operator[](std::size_t n) const -> const T &
constexpr friend auto operator==(const trivial_array &a, const trivial_array &b) noexcept -> bool
constexpr auto end() &noexcept -> T *
constexpr friend auto operator!=(const trivial_array &a, const trivial_array &b) noexcept -> bool
std::pair isn't constexpr enough, so I'm stuck with this. All I use it for is removing a temporary va...
Provides macros and basic templates used by the rest of kblib.
#define KBLIB_NODISCARD
This internal macro is used to provide a fallback for [[nodiscard]] in C++14.