Consider methods for metaprogramming patterns, if I have
std::vector<int> v;
v.push_back(42.42f);
this works mainly because the constructor used is not flagged explicit, in other words, my push_backtype is not safe.
Now I’m in a situation where I don’t even know how the container is declared v, in this case it is int, but I need to automatically output this type, having a common one std::vector<T>. I would like a solution T.
in C ++ 11 there is something like remove_all_extents(with a useful member type), but apparently this is only useful for old arrays, but this is basically what I would like to achieve.
I would like to raise an error when push_backit is not safe or type deduces, so that I can write a statement or implement something myself.
I really cannot find a working solution for this, it is so simple in theory, but as soon as the vector is declared, there is no explicit information about the type used for the elements.
I would also like to avoid explicit type inference, for example, translating foofrom my call to an ideal function
foo( container, elements ... )
to
foo<int>(container, elements ...)
where intis the type of elements container, it is also unsafe, it is also more detailed and error prone.
So, how do I get the type for container elements in C ++ 11?