Skip to content

Instantly share code, notes, and snippets.

@TheMaverickProgrammer
Created September 11, 2018 12:09
Show Gist options
  • Save TheMaverickProgrammer/520bd694cfc073e7189b41643df1b125 to your computer and use it in GitHub Desktop.
Save TheMaverickProgrammer/520bd694cfc073e7189b41643df1b125 to your computer and use it in GitHub Desktop.
#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