OK, so I have this little small corner of my code where I would like my function to return any of ( int , double , CString ) to clean up the code a bit.
So, I think: there is no problem writing a small unified shell struct with three members, etc. But wait! Didn't I read boost::variant ? Wasn't that exactly what I needed? That would save me from clutter with a wrapper structure! (Note that I already have a boost library available in my project.)
So, I launch my browser, go to Chapter 28. Boost.Variant and lo and behold:
The variant-variant template is a safe, general, stack-based discriminatory union container, offering a simple solution for manipulating an object from a heterogeneous set of types [...]
Excellent! That's what I need!
But then it continues:
Boost.Variant vs. Boost.any
- Boost.Any makes little use of template metaprogramming methods (avoiding potentially hard-to-read error messages and significant processor and memory requirements at compile time).
[...]
Troubleshooting
"Internal heap limit reached" - Microsoft Visual C ++. The compiler option / ZmNNN may increase the memory allocation limit. NNN represents the percentage of scaling (i.e. 100 indicates the default limit). (Try / Zm200.)
[...]
Oh oh Thus, using boost :: variant can significantly increase compilation time and generate hard-to-read error messages. What if someone moves my use of boost :: variant to a common header, will our project suddenly take longer to compile? Am I representing an (optional) complex type?
Should I use boost::variant for my simple tiny problem ?
source share