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

4

22

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?

Sideling answered 8/2, 2012 at 14:19 Comment(2)
No. (and filler)Lucilucia
Not everything in boost has been moved to std however nothing prevents you from using it in boost. I guess some boost libraries might be rewritten for C++11, some may be removed completely being rather redundant, although they will probably remain available for backward compatibility.Credendum
T
16

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

Tetrapody answered 8/2, 2012 at 14:43 Comment(1)
maybe you can update your answer to reflect 17 changes :)Allogamy
W
23

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

Whereof answered 9/6, 2015 at 16:46 Comment(1)
std::variant (similar to boost::variant) has also been standardized and will appear in C++17.Leta
T
16

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

Tetrapody answered 8/2, 2012 at 14:43 Comment(1)
maybe you can update your answer to reflect 17 changes :)Allogamy
A
8

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

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

Architectonic answered 12/10, 2016 at 6:49 Comment(0)
C
3

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.

Credendum answered 8/2, 2012 at 14:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.