提升还是不提升——这是一个问题

Promote or not promote - that is the questiion

本文关键字:问题 一个      更新时间:2023-10-16

此代码在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> .