C++11 标准是否提供类似 boost::any 的东西?

发布于 2025-01-03 05:58:07 字数 173 浏览 2 评论 0 原文

例如 boost::function 几乎完全移至 std::functionboost::shared_ptr 也是如此,

但我不能找到std::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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

软糖 2025-01-10 05:58:07

自从提出这个问题以来,我们就将 std::experimental::any 作为 可选功能已被投票排除在 C++14 标准之外。

至少在 GCC 5.1 中实现了

此后,该功能在 C++17 中标准化,形成 std::any 。另请参阅 C++17 的 std::variant 了解类型安全联合,它要么包含有限的已知类型替代方案之一,要么为空(感谢 remy-lebeau 的提示)。

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

染柒℉ 2025-01-10 05:58:07

并非 boost 中的每个库都将其纳入标准(即使是那些库也可能删除了组件)。一般来说,委员会在添加到标准库时相当保守(因为如果包含错误,以后几乎不可能删除某些内容(例如,因为有更好的替代方案))。

boost::functionboost::shared_ptr 几乎可以包含在内,因为它们已经是 tr1 的一部分。另一方面,boost::any 却没有成功。然而,它可能会在稍后被包含在标准库中(例如,在下一个技术报告中,请查看 此处)。虽然 boost::any 很不错,但我不会认为它像 shared_ptr 那样重要。

结论:boost::any 不是 C++11 的一部分,因为委员会认为没有迫切需要包含它

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

生来就爱笑 2025-01-10 05:58:07

Std::any 最近被接受为 c++17 标准:

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

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

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

花落人断肠 2025-01-10 05:58:07

我认为默认立场是图书馆不会被纳入新标准,除非它被提交并通过委员会。

我不确定 boost::any 是否已提交。可能不会。但是您仍然可以使用 boost::any。

我的猜测是,C++11 boost 库将被重写,其中一些将被认为是多余的,而另一些将被更改为使用移动语义、初始化列表和 auto,从而以具有 C++11 功能的 C++11 风格编写。

新库很可能全部采用 C++11 语言,但现有的 boost 包将在未来一段时间内保持可用,因为许多编译器尚未切换到 C++11 编译器。我还猜测,只有所有主要编译器实现的 C++11 功能才会首先进入包中。

对于程序员来说,这可能比 stackoverflow 更重要,对于 comp.std.c++.moderated 和 boost 邮件列表来说甚至更好。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文