Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 222
dev_null Avatar asked Feb 08 '12 14:02

dev_null


People also ask

Is boost part of the standard library C++?

Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work well with the C++ Standard Library. Boost libraries are intended to be widely useful, and usable across a broad spectrum of applications.

What is boost any?

The boost::any class (based on the class of the same name described in "Valued Conversions" by Kevlin Henney, C++ Report 12(7), July/August 2000) is a variant value type based on the second category. It supports copying of any value type and safe checked extraction of that value strictly against its type.

What did C++11 add?

C++11 includes new smart pointer classes: shared_ptr and the recently-added unique_ptr. Both are compatible with other Standard Library components, so you can safely store these smart pointers in standard containers and manipulate them with standard algorithms.

Does boost support C ++ 17?

Container not only supports this model with C++11 but also backports it to C++03 via boost::container::allocator_traits including some C++17 changes. This class offers some workarounds for C++03 compilers to achieve the same allocator guarantees as std::allocator_traits .


3 Answers

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

like image 168
Alexandre Pereira Nunes Avatar answered Oct 04 '22 21:10

Alexandre Pereira Nunes


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

like image 35
Grizzly Avatar answered Oct 04 '22 21:10

Grizzly


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

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

like image 41
user972014 Avatar answered Oct 04 '22 23:10

user972014