47 template <
typename T,
typename U>
66 #if 0 and KBLIB_USE_CXX17
74 template <
typename T, std::
size_t N>
83 template <
typename T, std::
size_t N>
104 return equal(
a.begin(),
a.end(), b.begin());
131 template <
typename U>
133 static_assert(std::is_unsigned<U>::value,
"U must be unsigned");
139 state = {b,
static_cast<U
>(
a + b)};
155 template <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];
176 template <
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());
183 inline namespace nums {
195 template <
typename T>
196 constexpr
operator T() const
197 noexcept(noexcept(
std::numeric_limits<T>::
max())) {
200 template <
typename T>
202 noexcept(
std::numeric_limits<T>::
max())) {
209 template <
typename L,
typename R>
212 return std::less<>{}(lhs, rhs) ? std::forward<R>(rhs)
213 : std::forward<L>(lhs);
241 template <
typename T>
245 template <
typename T>
249 template <
typename T>
253 template <
typename T>
258 template <
typename T>
262 template <
typename T>
266 template <
typename T>
270 template <
typename T>
275 template <
typename T>
279 template <
typename T>
283 template <
typename T>
287 template <
typename T>
305 template <
typename T>
306 constexpr
operator T() const
307 noexcept(noexcept(
std::numeric_limits<T>::
min())) {
310 template <
typename T>
312 noexcept(
std::numeric_limits<T>::
min())) {
319 template <
typename L,
typename R>
322 return std::less<>{}(lhs, rhs) ? std::forward<R>(lhs)
323 : std::forward<L>(rhs);
326 template <
typename T>
330 template <
typename T>
334 template <
typename T>
338 template <
typename T>
343 template <
typename T>
347 template <
typename T>
351 template <
typename T>
355 template <
typename T>
360 template <
typename T>
364 template <
typename T>
368 template <
typename T>
372 template <
typename T>
456 template <
typename T =
double>
458 return 3.1415926535897932384626433832795028841971693993751l;
460 template <
typename T =
double>
464 template <
typename T =
double>
466 return 2.7182818284590452353602874713526624977572470937000l;
468 template <
typename T =
double>
470 return 1.4142135623730950488016887242096980785696718753769l;
472 template <
typename T =
double>
474 return 1.6180339887498948482045868343656381177203091798058l;
478 template <
typename A,
typename F>
481 and std::is_unsigned<A>::value,
488 return static_cast<A
>(x);
493 template <
typename A,
typename F>
495 -> enable_if_t<std::is_integral<A>::value and std::is_integral<F>::value
496 and std::is_signed<A>::value
497 and std::is_signed<F>::value,
508 template <
typename A,
typename F>
510 -> enable_if_t<std::is_integral<A>::value and std::is_integral<F>::value
511 and std::is_signed<A>::value
512 and std::is_unsigned<F>::value,
533 template <
typename T,
typename F>
536 static_assert(std::is_unsigned<T>::value,
"Destination must be unsigned.");
537 return static_cast<T
>((val - low) *
static_cast<T
>(
max) * delta);
549 template <
typename T,
typename F>
552 static_assert(std::is_unsigned<T>::value,
"Destination must be unsigned.");
553 auto delta = (high - low) /
static_cast<T
>(
max);
554 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
The main namespace in which all entities from kblib are defined.
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
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 static auto of() noexcept(noexcept(std::numeric_limits< T >::max()))
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 static auto of() noexcept(noexcept(std::numeric_limits< T >::min()))
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
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.