
On 9 Feb 2011, at 22:29, Kim Barrett wrote:
On Feb 9, 2011, at 12:38 PM, Adarsh Soodan wrote:
I was curious if others have solved similar performance problems. I couldn't use boost::variant because I needed it for a message passing library where library user can pass in any message type. boost::variant would have been restrictive if the user wanted to use too many top level types of messages.
I would be interested in having boost::any (or some variation on it) providing small buffer optimization. That was done for boost::function back around boost 1.34, and something like that would work just fine for my usage. I've given the SBO for boost::any problem a cursory look, but have not yet demonstrated a sufficiently bad performance problem for use there to convince my managers that I should work on that rather than something else.
I believe spirit/home/support/detail/hold_any.hpp contains something like boost::any, with a small buffer optimisation. This is not suitable for directly copying out into general boost. In particular I believe it assume any type held in the 'any' is streamable, and quite possibly doesn't consider issues of exception safety. On the subject of exception safety, I quite like how boost::variant will put a 'boost::blank' in (if that exists in the variant) if the value is lost. A similar 'empty' state for boost::any might solve problems with exception safety, at least for me. Chris