CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    Join Date
    Jun 2009
    Posts
    8

    Re: memory errors with std::map

    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).

  2. #17
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: memory errors with std::map

    Quote Originally Posted by rilpo View Post
    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.

    - 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.

    - 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.....

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured