blob: 309f0884e4a7b7330c95391abe44b980a2f5c432 [file] [log] [blame]
Eric Fiselier257fd692016-05-07 01:04:55 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9#ifndef SUPPORT_TYPE_ID_H
10#define SUPPORT_TYPE_ID_H
11
12#include <functional>
13#include <cassert>
14
15#include "test_macros.h"
16
17#if TEST_STD_VER < 11
18#error This header requires C++11 or greater
19#endif
20
21// TypeID - Represent a unique identifier for a type. TypeID allows equality
22// comparisons between different types.
23struct TypeID {
24 friend bool operator==(TypeID const& LHS, TypeID const& RHS)
25 {return LHS.m_id == RHS.m_id; }
26 friend bool operator!=(TypeID const& LHS, TypeID const& RHS)
27 {return LHS.m_id != RHS.m_id; }
28private:
29 explicit constexpr TypeID(const int* xid) : m_id(xid) {}
30
31 TypeID(const TypeID&) = delete;
32 TypeID& operator=(TypeID const&) = delete;
33
34 const int* const m_id;
35 template <class T> friend TypeID const& makeTypeID();
36
37};
38
39// makeTypeID - Return the TypeID for the specified type 'T'.
40template <class T>
41inline TypeID const& makeTypeID() {
42 static int dummy;
43 static const TypeID id(&dummy);
44 return id;
45}
46
47template <class ...Args>
48struct ArgumentListID {};
49
50// makeArgumentID - Create and return a unique identifier for a given set
51// of arguments.
52template <class ...Args>
53inline TypeID const& makeArgumentID() {
54 return makeTypeID<ArgumentListID<Args...>>();
55}
56
57#endif // SUPPORT_TYPE_ID_H