aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/interface/mpl.h
blob: 9865e28b6c3e4a6da089041eb56d6b477e66e4ab (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
63
64
65
66
67
68
69
70
71
72
73
#pragma once

#include "fwd.h"

#include <tuple>
#include <type_traits>

namespace NYT {

/// @cond Doxygen_Suppress

////////////////////////////////////////////////////////////////////////////////

template <class TBase, class TDerived>
struct TIsBaseOf
{
    static constexpr bool Value = std::is_base_of_v<TBase, TDerived> && !std::is_same_v<TBase, TDerived>;
};

////////////////////////////////////////////////////////////////////////////////

namespace NDetail {

template <class T, class Tuple>
struct TIndexInTuple;

template <class T, class... Types>
struct TIndexInTuple<T, std::tuple<T, Types...>>
{
    static constexpr int Value = 0;
};

template <class T>
struct TIndexInTuple<T, std::tuple<>>
{
    static constexpr int Value = 0;
};

template <class T, class U, class... Types>
struct TIndexInTuple<T, std::tuple<U, Types...>>
{
    static constexpr int Value = 1 + TIndexInTuple<T, std::tuple<Types...>>::Value;
};

template <class T, class TTuple>
constexpr bool DoesTupleContainType = (TIndexInTuple<T, TTuple>::Value < std::tuple_size<TTuple>{});

template <class TOut, class TIn = std::tuple<>>
struct TUniqueTypes;

template <class... TOut, class TInCar, class... TInCdr>
struct TUniqueTypes<std::tuple<TOut...>, std::tuple<TInCar, TInCdr...>>
{
    using TType = std::conditional_t<
        DoesTupleContainType<TInCar, std::tuple<TOut...>>,
        typename TUniqueTypes<std::tuple<TOut...>, std::tuple<TInCdr...>>::TType,
        typename TUniqueTypes<std::tuple<TOut..., TInCar>, std::tuple<TInCdr...>>::TType
    >;
};

template <class TOut>
struct TUniqueTypes<TOut, std::tuple<>>
{
    using TType = TOut;
};

} // namespace NDetail

/// @endcond Doxygen_Suppress

////////////////////////////////////////////////////////////////////////////////

}