Is there any way to get the size (in bytes) of the data stored by std::any
? The only workaround I came up with is querying the type of its value by std::any::type
and comparing the result to a list of known types like my_any.type() == typeid(T)
, then the size is sizeof(T)
. Unfortunately, this solution only works when the types are known beforehand.
Do you know any solution?
any::size()
does not much improve the question, tough it may help to expose XY problems.) – Savick