#pragma once #include #include "util.hh" namespace types { // A very basic typeid: Using the constexpr __PRETTY_FUNCTION__ array slicing trick we used for `exopt::util::type_name()`, we can extract the unmangled, de-aliased type name T, we can then hash that at comptime, and give it static storage: Therefore __PRETTY_FUNCTION__ will not be given storage, but the resulting (far smaller, but still *almost* unique to each type name) hash, will be. using util::type_name; template struct type_hash_of { // Give *only* the computed hash static storage duration, not the type name. constexpr static inline auto value = sha256::compute(util::type_name_literal()); }; /// Returns a (semi) unique SHA256 hash representing the type `T`. /// /// NOTE: This hash is given static storage duration, but nothing else used to calculate it is. Therefore executable bloat is not a concern for values obtained from this function. template constexpr const auto& type_hash() noexcept { constexpr const auto& value = type_hash_of::value; return value; } template constexpr inline auto& type_hash_v = type_hash_of::value; }