|
Boost Users : |
From: Dizzy (dizzy_at_[hidden])
Date: 2007-03-19 04:41:31
Hello
In order to minimize heap allocations but still allow for some OOP designs I
needed a sort of union but one that it works for more than POD types. So I
implemented such a thing myself to find out recently that boost::variant
might do this already (boost does that often ;) ).
However, initial testing for boost::variant shows that that there is no
compile time check on the types allowed to instantiate boost::get on a
variant, example:
struct A {}; struct B {}; struct C{};
int main()
{
boost::variant v<A, B> v;
boost::get<C>(v);
}
Compiles fine (gcc 4.1.1, boost 1.33.1) but errors at runtime throwing a
bad_get exception from get. It seems to me that the get<> on variant somehow
works for any type not checking if the type parameter for get matches one in
the type sequence of the given variant.
Maybe I miss something but shouldn't get on variant have a compile time type
check ? (this would catch at compile time common errors for variant use cases
I think)
-- Mihai RUSU Email: dizzy_at_[hidden] GPG : http://dizzy.roedu.net/dizzy-gpg.txt WWW: http://dizzy.roedu.net "Linux is obsolete" -- AST
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net