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

2019-02-11 21:04发布

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?

4条回答
Fickle 薄情
2楼-- · 2019-02-11 21:44

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

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

查看更多
虎瘦雄心在
3楼-- · 2019-02-11 22:01

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

查看更多
手持菜刀,她持情操
4楼-- · 2019-02-11 22:04

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

查看更多
虎瘦雄心在
5楼-- · 2019-02-11 22:05

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.

查看更多
登录 后发表回答