I need a “placeholder” value of a (parametric) bits type, for type stability, in certain branches of my code. Ie I need a function f
such that f(T) isa T
. When T <: Number
, zero(T)
works, but I need something more general.
I am not sure what the best way of doing this is though. I thought of the following:
any_value1(T) = reinterpret(T, Vector{UInt8}(sizeof(T)))
any_value2(T) = Vector{T}(1)[1]
any_value3(T) = unsafe_get(Nullable{T}())
All work, yet I pity my future self who is going to read any of them later on. Is there anything more idiomatic?