This documentation is automatically generated by competitive-verifier/competitive-verifier
#include "tools/bit_ceil.hpp"
template <typename T>
constexpr T bit_ceil(T x);
It returns the following value.
\[\begin{align*} \left\{\begin{array}{ll} 1 & \text{(if $x = 0$)}\\ 2^{\lceil \log_2(x) \rceil} & \text{(if $x > 0$)} \end{array}\right.& \end{align*}\]<T>
is a built-in integral type, tools::int128_t
or tools::uint128_t
.T
.#ifndef TOOLS_BIT_CEIL_HPP
#define TOOLS_BIT_CEIL_HPP
#include <bit>
#include <cassert>
#include <type_traits>
#include "tools/is_integral.hpp"
#include "tools/is_signed.hpp"
#include "tools/make_unsigned.hpp"
namespace tools {
template <typename T>
constexpr T bit_ceil(T) noexcept;
template <typename T>
constexpr T bit_ceil(const T x) noexcept {
static_assert(::tools::is_integral_v<T> && !::std::is_same_v<::std::remove_cv_t<T>, bool>);
if constexpr (::tools::is_signed_v<T>) {
assert(x >= 0);
return ::tools::bit_ceil<::tools::make_unsigned_t<T>>(x);
} else {
return ::std::bit_ceil(x);
}
}
}
#endif
#line 1 "tools/bit_ceil.hpp"
#include <bit>
#include <cassert>
#include <type_traits>
#line 1 "tools/is_integral.hpp"
#line 5 "tools/is_integral.hpp"
namespace tools {
template <typename T>
struct is_integral : ::std::is_integral<T> {};
template <typename T>
inline constexpr bool is_integral_v = ::tools::is_integral<T>::value;
}
#line 1 "tools/is_signed.hpp"
#line 5 "tools/is_signed.hpp"
namespace tools {
template <typename T>
struct is_signed : ::std::is_signed<T> {};
template <typename T>
inline constexpr bool is_signed_v = ::tools::is_signed<T>::value;
}
#line 1 "tools/make_unsigned.hpp"
#line 5 "tools/make_unsigned.hpp"
namespace tools {
template <typename T>
struct make_unsigned : ::std::make_unsigned<T> {};
template <typename T>
using make_unsigned_t = typename ::tools::make_unsigned<T>::type;
}
#line 10 "tools/bit_ceil.hpp"
namespace tools {
template <typename T>
constexpr T bit_ceil(T) noexcept;
template <typename T>
constexpr T bit_ceil(const T x) noexcept {
static_assert(::tools::is_integral_v<T> && !::std::is_same_v<::std::remove_cv_t<T>, bool>);
if constexpr (::tools::is_signed_v<T>) {
assert(x >= 0);
return ::tools::bit_ceil<::tools::make_unsigned_t<T>>(x);
} else {
return ::std::bit_ceil(x);
}
}
}