Re: memory errors with std::map
Quote:
If you want to store one of a limited set of built-in types, consider using boost::variant.
Thanks for the advice. I've looked at this solution (few months ago and for another project).
In my case, there were some reasons no to use it :
- of course it is required to link with boost and it seems to me (personal point of view) that boost does not maintain stable branches and so API is not stable (change of version) or bugs are not fixed in earlier versions. I very like boost but there is a cost of using it. And Boost::variant won't be in the C++0X standard (If I'm right).
- Variant is for built-in types only and that's not my case.
- and finaly maybe less obvious, If you want to let the "user" to be able to implement his own MyValue and to store these obects in this container Variant is not adapted. Moreover the template is limited with 10 arguments (but maybe we can set it higher).
Re: memory errors with std::map
Quote:
Originally Posted by
rilpo
Thanks for the advice. I've looked at this solution (few months ago and for another project).
In my case, there were some reasons no to use it :
- of course it is required to link with boost and it seems to me (personal point of view) that boost does not maintain stable branches and so API is not stable (change of version) or bugs are not fixed in earlier versions. I very like boost but there is a cost of using it. And Boost::variant won't be in the C++0X standard (If I'm right).
The API is relatively stable, and the variant library is header-only so no linking required.
Quote:
- Variant is for built-in types only and that's not my case.
I believe it's actually safe for any type. That's what sets it apart from unions.
Quote:
- and finaly maybe less obvious, If you want to let the "user" to be able to implement his own MyValue and to store these obects in this container Variant is not adapted. Moreover the template is limited with 10 arguments (but maybe we can set it higher).
That limit will be lifted just as soon as any of the compiler vendors get around to implementing C++0x variadic templates.....