Created
September 11, 2018 12:09
-
-
Save TheMaverickProgrammer/520bd694cfc073e7189b41643df1b125 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "cx_murmur3.h" | |
//---------------------------------------------------------------------------- | |
// constexpr typeid | |
namespace cx | |
{ | |
namespace err | |
{ | |
namespace | |
{ | |
extern const char* typeid_runtime_error; | |
} | |
} | |
template <typename T> | |
struct typeid_t | |
{ | |
template <typename> | |
friend constexpr uint32_t type_id(); | |
private: | |
constexpr static const char* name() | |
{ | |
#ifdef _MSC_VER | |
// this is untested: __FUNCDNAME__ or __FUNCSIG__ ? | |
return __FUNCDNAME__; | |
#else | |
return __PRETTY_FUNCTION__; | |
#endif | |
} | |
constexpr static uint32_t id = murmur3_32(name(), 0); | |
}; | |
template <typename T> | |
constexpr uint32_t type_id() | |
{ | |
return true ? typeid_t<T>::id : | |
throw err::typeid_runtime_error; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment