提升还是不提升——这是一个问题
Promote or not promote - that is the questiion
此代码在Visual c++ 11 Developer Preview中可以正常编译,但在gcc 4.6.1中无法编译。
如何使其对后者"可编译"?
#ifndef PROMOTE_H_INCLUDED
#define PROMOTE_H_INCLUDED
#include <boostmplvector.hpp>
#include <boostmplfind.hpp>
#include <boostmplnext.hpp>
#include <boostmplderef.hpp>
namespace mpl = boost::mpl;
template<class Integral>
struct Promote
{
typedef mpl::vector<char,short,int,long,long long> types;
typedef typename mpl::find<types,Integral>::type this_type;
typedef typename mpl::next<this_type>::type next_type;
typedef typename mpl::deref<next_type>::type type;
};
#endif // PROMOTE_H_INCLUDED
,然后在main:
cout << typeid( Promote<int>::type).name() ;
修改include指令:
#include <boost/mpl/vector.hpp>
这将在Windows和unix类型的系统上工作。
没有检测到其他语法问题(但因为这只是一个模板,我不知道当你实际使用它时是否有问题)。
编辑:与你在main中添加的内容一起,它将使用GCC 4.6.1进行编译。
别忘了#include <typeinfo>
.
相关文章:
- 一个关于在C++中重载布尔运算符的问题
- 发送一个带有libcurl C++问题的帖子请求:s
- 在决定是通过参考还是通过价值时,尺寸真的是一个问题吗
- 在用于格式4的arm模拟器中实现功能时的一个问题
- 我试图制作一个程序,要求用户输入问题和答案,但程序循环不正确
- 使用运算符 [] 引用 std::vector 上最后一个元素时出现问题<>
- 为我的 c++ 类介绍制作一个三角形分类器.我有几个问题
- 关于复制构造函数的一个棘手问题
- Tmax(0x7fffffff 的一个奇怪问题,为什么 (!x) == x?
- C++线程安全:如果只有一个线程可以写入非原子变量,但多个线程从中读取. 会遇到问题吗?
- 我正在尝试解决一个需要数组总和值但代码不起作用的问题,我想做这样的事情
- 在解决链表问题时创建一个额外的节点是一个好习惯吗?
- 存储另一个函数返回的布尔数组时遇到问题
- 为什么在分配给成员变量之前获取unique_ptr的返回是一个问题?
- 我在使用 boost::serialization 时遇到了一个问题,我的代码在 Linux 中运行良好,但在 Wind
- 我有一个关于C++提升的问题:: asio 和 std :: 异步
- 这是一个二叉搜索树吗?黑客排名问题
- 几对性能问题(一个较大的向量与较小的块向量),值得存储迭代索引以进行矢量访问
- GLSL问题:一个程序中有多个着色器
- 设计问题——一个函数调用所有三个函数