Does C++11 standard provide something like boost::any?

送分小仙女□ 提交于 2019-12-18 18:47:17

问题


for example boost::function is moved almost entirely to std::function, the same is with boost::shared_ptr

But I can't find std::any? Was it renamed or was not it placed in new standard at all by any reason?


回答1:


Not every library from boost makes it into the standard (and even those that do may have components removed). Generally the commitee is pretty conservative when it comes to adding to the standardlibrary (since it's next to impossible to get something removed at a later point if the inclusion was a mistake (.e.g. because there is a better alternative)).

boost::function and boost::shared_ptr where pretty much a given for inclusion since they where already part of tr1. boost::any on the other hand did not make the cut. It might however be included in the standard library at a later point (e.g. in the next technical report, look here). While boost::any is nice to have, I wouldn't rate it as quite as important as e.g. shared_ptr.

Concluding: boost::any is not part of C++11, since the committee didn't see any pressing need to include it




回答2:


Since the question was asked, we advanced towards std::experimental::any as an optional feature voted out of C++14 standard.

It was then implemented in GCC 5.1, at least.

The feature was since then standardized in C++17 resulting in std::any. See also C++17's std::variant for a type-safe union which either holds one of a limited known-types alternative, or is empty (thanks remy-lebeau for the tip).




回答3:


Std::any was recently accepted into the c++17 standard:

http://en.cppreference.com/w/cpp/utility/any




回答4:


I think the default position was that a library would NOT be included in the new standard unless it was submitted to be included and then passed the committee.

I am not sure if boost::any was ever submitted. Probably not. However you can still use boost::any.

My guess is that with C++11 boost libraries will be rewritten, some will be considered redundant and others will be changed to use move semantics, initializer lists and auto thus being written in C++11 style with C++11 features.

Most likely new libraries will all be in C++11 but existing boost packages will be kept as available for some time to come as many will not have switched to C++11 compilers yet. I would also guess that only features of C++11 that are implemented by all the main compilers will go into the package at first.

This is probably more a question for programmers than stackoverflow, and even better for comp.std.c++.moderated and boost mailing lists.



来源:https://stackoverflow.com/questions/9195078/does-c11-standard-provide-something-like-boostany

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!