【问题标题】:Promote or not promote - that is the questiion宣传还是不宣传——这是个问题
【发布时间】:2011-10-22 10:19:52
【问题描述】:

此代码在 Visual C++ 11 Developer Preview 中可以正常编译,但在 gcc 4.6.1 中无法编译。

如何使它对后者“可编译”?

#ifndef PROMOTE_H_INCLUDED
#define PROMOTE_H_INCLUDED
#include <boost\mpl\vector.hpp>
#include <boost\mpl\find.hpp>
#include <boost\mpl\next.hpp>
#include <boost\mpl\deref.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() ;

【问题讨论】:

    标签: c++ boost boost-mpl


    【解决方案1】:

    更改包含指令:

    #include <boost/mpl/vector.hpp>
    

    这适用于 Windows 和 Unix 类型的系统。

    没有检测到其他语法问题(但由于这只是一个模板,我不知道你实际使用时是否有问题)。

    编辑:使用您在主文件中添加的内容,它可以使用 GCC 4.6.1 进行编译。
    别忘了#include &lt;typeinfo&gt;

    【讨论】:

    • 很好看,我永远不记得哪个斜线是“正确的”斜线。确实它现在有效。谢谢。
    • 你会经常在 Windows 上使用 / ,但在类 Unix 系统上使用 \ 基本上不会有任何工作。 (顺便说一句,我相信 include 指令的处理方式是由实现定义的,因此两者都不是普遍安全的。)
    猜你喜欢
    • 1970-01-01
    • 2013-11-11
    • 1970-01-01
    • 2021-10-21
    • 2012-05-27
    • 1970-01-01
    • 1970-01-01
    • 2020-01-14
    • 1970-01-01
    相关资源
    最近更新 更多