什么是升压相当于::变体STD C ++? [英] What is the equivalent of boost::variant in std c++?

查看:162
本文介绍了什么是升压相当于::变体STD C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找替代C风格的结合。提高::变种就是这样的一个选项。是否有性病ç什么++?

 工会{
   INT I;
   双D;
}


解决方案

由于一些评论说:不,有标准C无升压变酷似++。也许在几年内就会有,但为什么要等 - 使用升压变今天


编辑(四年后,2016年):的在C ++ 17会有的std ::变种。相似但不完全相同的boost ::变种。所以,当你的编译器支持C ++ 17,你将不得不在标准库的解决方案。

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;
}

解决方案

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!


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.

这篇关于什么是升压相当于::变体STD C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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