summaryrefslogtreecommitdiffstats
path: root/yql/essentials/minikql/mkql_numeric_cast.h
blob: 954f741e98f8765b6fcc5095ec0de5533828fc09 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once

#include <yql/essentials/public/decimal/yql_wide_int.h>

#include <type_traits>

namespace NKikimr {
namespace NMiniKQL {

// TMakeUnsigned - a safe alternative to std::make_unsigned that avoids UB
// when specializing for custom types like NYql::TWide
template <typename T>
struct TMakeUnsigned {
    using type = std::make_unsigned_t<T>;
};

template <typename T>
using TMakeUnsigned_t = typename TMakeUnsigned<T>::type;

// Specializations for NYql::TWide types
template <>
struct TMakeUnsigned<NYql::TWide<i8>> {
    using type = NYql::TWide<ui8>;
};

template <>
struct TMakeUnsigned<NYql::TWide<ui8>> {
    using type = NYql::TWide<ui8>;
};

template <>
struct TMakeUnsigned<NYql::TWide<i16>> {
    using type = NYql::TWide<ui16>;
};

template <>
struct TMakeUnsigned<NYql::TWide<ui16>> {
    using type = NYql::TWide<ui16>;
};

template <>
struct TMakeUnsigned<NYql::TWide<i32>> {
    using type = NYql::TWide<ui32>;
};

template <>
struct TMakeUnsigned<NYql::TWide<ui32>> {
    using type = NYql::TWide<ui32>;
};

template <>
struct TMakeUnsigned<NYql::TWide<i64>> {
    using type = NYql::TWide<ui64>;
};

template <>
struct TMakeUnsigned<NYql::TWide<ui64>> {
    using type = NYql::TWide<ui64>;
};

} // namespace NMiniKQL
} // namespace NKikimr