I came up with this:
template <class T> struct var {
using hash_type = unsigned;
using value_type = T;
value_type value;
const hash_type cached_id;
constexpr var(const value_type the_value) noexcept
: value(the_value)
, cached_id([]{ static hash_type k; return k++; }())
{}
constexpr operator auto() noexcept { return value; }
};
template <class T> var(T const&) -> var<T>;
Live on Compiler Explorer
No macros.
Is this what you're looking for?