52 lines
1.2 KiB
C++
52 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <type_traits>
|
|
#include <utility>
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
|
|
namespace util {
|
|
|
|
namespace detail {
|
|
|
|
template <typename T, T Offset, T... Ints>
|
|
inline constexpr std::integer_sequence<T, (Offset + Ints)...> add_offset(std::integer_sequence<T, Ints...>)
|
|
{
|
|
return {};
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
template <typename T, T Offset, T N>
|
|
inline constexpr auto make_offset_integer_sequence()
|
|
{
|
|
return detail::add_offset<T, Offset>(std::make_integer_sequence<T, N>{});
|
|
}
|
|
|
|
template <std::size_t Offset, std::size_t N>
|
|
inline constexpr auto make_offset_index_sequence()
|
|
{
|
|
return make_offset_integer_sequence<std::size_t, Offset, N>();
|
|
}
|
|
|
|
template <typename Fn, std::size_t... Ints>
|
|
constexpr auto for_constexpr(Fn &&func, std::index_sequence<Ints...>)
|
|
{
|
|
if constexpr (std::is_void_v<std::invoke_result_t<Fn, std::integral_constant<std::size_t, 0>>>) {
|
|
(func(std::integral_constant<std::size_t, Ints>{}), ...);
|
|
} else {
|
|
if ((func(std::integral_constant<std::size_t, Ints>{}) && ...))
|
|
return true;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
template <typename...>
|
|
struct always_false : std::false_type {
|
|
};
|
|
template <typename... Ts>
|
|
inline constexpr auto always_false_v = always_false<Ts...>::value;
|
|
|
|
} // namespace util
|