7 #ifndef TURI_BASIC_TYPES_H_ 8 #define TURI_BASIC_TYPES_H_ 10 #include <core/logging/assertions.hpp> 14 template<
typename Target,
typename Source,
int UnusedParam>
struct truncate_check_impl {
15 Target operator()(Source x);
18 template<
typename Target,
typename Source> Target truncate_check(Source x) {
19 return truncate_check_impl<Target, Source, 0>()(x);
22 template<
typename Target,
typename Source>
struct truncate_check_impl<Target, Source, 0> {
23 Target operator()(Source x) {
24 static_assert(!std::is_same<Source, Source>::value,
"Unknown instantiation of truncate_check");
29 template<>
struct truncate_check_impl<int64_t, size_t, 0> {
30 int64_t operator()(
size_t x) {
31 ASSERT_LT(x, (1ULL << 63));
32 return static_cast<int64_t
>(x);
37 template<
typename T> T ceil_divide(T n, T m) {
38 return (n + (m-1)) / m;