C ++标准库中的boost :: variant等效于什么? [英] What is the equivalent of boost::variant in the C++ standard library?

查看:123
本文介绍了C ++标准库中的boost :: variant等效于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找C风格联合的替代方案。 boost :: variant是这样一种选择。 std C ++中有什么吗?

I am looking for an alternative to C-style union. boost::variant is one such option. Is there anything in std C++ ?

union {
   int i;
   double d;
}


推荐答案

正如一些评论者所说: ,标准C ++中没有Boost Boost-like。也许会在几年后出现,但是为什么要等待-今天就使用Boost Variant!

As several commenters said: No, there is no Boost Variant-alike in standard C++. Maybe in a few years there will be, but why wait--use Boost Variant today!

编辑(四年后,2016年):在C ++ 17中将有 std :: variant 。与 boost :: variant 类似但不相同。因此,当您的编译器支持C ++ 17时,您将在标准库中找到一个解决方案。

Edit (four years later, 2016): In C++17 there will be std::variant. Similar but not identical to boost::variant. So when your compiler supports C++17, you will have a solution in the standard library.

这篇关于C ++标准库中的boost :: variant等效于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆