Skip to content

Instantly share code, notes, and snippets.

@ryutorion
Created August 8, 2021 14:09
Show Gist options
  • Save ryutorion/c32c7307ede0caf57d42ea61975a9fff to your computer and use it in GitHub Desktop.
Save ryutorion/c32c7307ede0caf57d42ea61975a9fff to your computer and use it in GitHub Desktop.
#ifndef UTILITY_H_INCLUDED
#define UTILITY_H_INCLUDED
#include <cstdint>
#include <bit>
template <uint64_t N>
[[nodiscard]]
constexpr uint64_t multipleof(const uint64_t value) noexcept
{
static_assert(std::popcount(N) == 1);
return (value + N - 1) & ~(N - 1);
}
#endif // UTILITY_H_INCLUDED
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment