blob: 309f0884e4a7b7330c95391abe44b980a2f5c432 [file] [log] [blame]
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef SUPPORT_TYPE_ID_H
#define SUPPORT_TYPE_ID_H
#include <functional>
#include <cassert>
#include "test_macros.h"
#if TEST_STD_VER < 11
#error This header requires C++11 or greater
#endif
// TypeID - Represent a unique identifier for a type. TypeID allows equality
// comparisons between different types.
struct TypeID {
friend bool operator==(TypeID const& LHS, TypeID const& RHS)
{return LHS.m_id == RHS.m_id; }
friend bool operator!=(TypeID const& LHS, TypeID const& RHS)
{return LHS.m_id != RHS.m_id; }
private:
explicit constexpr TypeID(const int* xid) : m_id(xid) {}
TypeID(const TypeID&) = delete;
TypeID& operator=(TypeID const&) = delete;
const int* const m_id;
template <class T> friend TypeID const& makeTypeID();
};
// makeTypeID - Return the TypeID for the specified type 'T'.
template <class T>
inline TypeID const& makeTypeID() {
static int dummy;
static const TypeID id(&dummy);
return id;
}
template <class ...Args>
struct ArgumentListID {};
// makeArgumentID - Create and return a unique identifier for a given set
// of arguments.
template <class ...Args>
inline TypeID const& makeArgumentID() {
return makeTypeID<ArgumentListID<Args...>>();
}
#endif // SUPPORT_TYPE_ID_H