aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/misc/typeid-inl.h
blob: a4518cfa46c7e082945d1d05e36397092f922417 (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
#ifndef TYPEID_INL_H_
#error "Direct inclusion of this file is not allowed, include typeid.h"
// For the sake of sane code completion.
#include "typeid.h"
#endif

#include "port.h"

#include <util/system/compiler.h>

namespace NYT {

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

namespace NDetail {

template <class T>
class TTypeidTag
{ };

} // namespace NDetail

template <class T>
const std::type_info& Typeid()
{
    if constexpr (requires { TypeidImpl(NDetail::TTypeidTag<T>()); }) {
        return TypeidImpl(NDetail::TTypeidTag<T>());
    } else {
        return typeid(T);
    }
}

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

#undef YT_DECLARE_TYPEID
#undef YT_DEFINE_TYPEID

#define YT_DECLARE_TYPEID(type) \
    [[maybe_unused]] YT_ATTRIBUTE_USED const std::type_info& TypeidImpl(::NYT::NDetail::TTypeidTag<type>);

#define YT_DEFINE_TYPEID(type) \
    [[maybe_unused]] YT_ATTRIBUTE_USED Y_FORCE_INLINE const std::type_info& TypeidImpl(::NYT::NDetail::TTypeidTag<type>) \
    { \
        return typeid(type); \
    }

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

} // namespace NYT