简体   繁体   中英

Differences between `boost::any` and `std::any`

C++17 introduces the object container std::any , based on the boost library boost::any . My question is: Is the standardized any equivalent to the boost version, or are there differences?

A similar question has been posted about variant , and some differences exist in that case, but I could not find references about any .


EDIT: A difference I could see is the availability of the methods emplace . More than a difference in the API I'm interested to the differences between the behavior and the guarantees. For instance, different allocations would be significant for me.

I'm interested to the differences between the behavior and the guarantees.

There aren't any behavioral differences; not really. They both have the same requirements on the ValueType (copy-constructible, and a destructor that doesn't emit exceptions). They both provide the same operations on the values they store, with pretty much identical exception guarantees.

The principle difference is that boost::any 's implementation at present doesn't implement small object optimization, while std::any implementations may provide it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM