2011-10-27 11 views
-3

以下このコードは、VS2010で正常にコンパイルが、gccでコンパイルする必要はありません4.6.1:はgccでコードをコンパイルすることはできません4.6.1

#ifndef IS_CHAR_H_INCLUDED 
#define IS_CHAR_H_INCLUDED 
#include <type_traits> 

template<class Int_T> 
struct Is_Char_ 
{ 
    enum {value = false}; 
}; 

template<> 
struct Is_Char_<char> 
{ 
    enum {value = true}; 
}; 

template<> 
struct Is_Char_<unsigned char> 
{ 
    enum {value = true}; 
}; 

template<> 
struct Is_Char_<signed char> 
{ 
    enum {value = true}; 
}; 

template<class Int_T> 
struct Is_Char : Is_Char_<typename std::remove_cv<Int_T>::type> 
{ 

}; 

#endif // IS_CHAR_H_INCLUDED 

#ifndef PROMOTE_H_INCLUDED 
#define PROMOTE_H_INCLUDED 
#include <type_traits> 
#include <boost/mpl/vector.hpp> 
#include <boost/mpl/find.hpp> 
#include <boost/mpl/next.hpp> 
#include <boost/mpl/deref.hpp> 
#include <boost/mpl/end.hpp> 
    //#include "Is_Char.h" doesn't have to be here this file is pasted above 


/*Promotes Integer type to one up in size range*/ 
template<class Integer> 
struct Promote 
{ 
    static_assert(std::is_integral<Integer>::value,"Non Integer type is not allowed."); 
    /*Check correct type - depending on Integer being signed or unsigned*/ 
    typedef typename std::conditional<std::is_signed<Integer>::value, 
           boost::mpl::vector<signed char,short,int,long,long long>, 
    boost::mpl::vector<unsigned char,unsigned short,unsigned int,long,long long> 
            >::type types; 
    /* 
    Find this type from the list above - substituting Integer for signed or unsigned char iff Integer is of type char 
    */ 
    typedef typename boost::mpl::find<types, 
    typename std::conditional<Is_Char<Integer>::value, 
    typename std::conditional<std::is_signed<Integer>::value,signed char,unsigned char>::type, Integer>::type>::type this_type; 

    /*If Integer is int and if size of it is == to long promote int to long long (iterate to next element twice)*/ 
    typedef typename boost::mpl::eval_if<boost::mpl::bool_<((std::is_same<Integer,int>::value || std::is_same<Integer,unsigned int>::value) 
                   && (sizeof(int) == sizeof(long)))>, 
             boost::mpl::next<typename boost::mpl::next<this_type>::type>, 
             boost::mpl::next<this_type> 
             >::type next_type; 
    /*Check if iterator points within range or if one pass end which means that Integer was u/long long*/ 
    typedef typename std::conditional<std::is_same<typename boost::mpl::end<types>::type,next_type>::value,Integer,typename boost::mpl::deref<next_type>::type>::type type; 
}; 

#endif // PROMOTE_H_INCLUDED 
+1

エラーメッセージを追加してください。 – Patrick

+0

gccによってどのようなエラーが報告されますか? –

+0

コンパイラから受け取ったエラーを含めることはできますか? – Ciaran

答えて

1

私の推測では、あなたが --std=c++0xを指定していないということですコンパイル時には、 std::is_integral<>などのC++ 11の機能は使用できません。そのオプションを使用するとコードがコンパイルされます。

更新:コンパイラの出力が表示されたので、問題の可能性があるすべての警告を有効にして、-Wpedantic-errorsを設定してエラーの一部として扱うという問題がありました。これらの警告の多くは完全に合理的なコードによって引き起こされ、ほとんどの著者(Boostを含む)はそれらのすべてを修正または回避する時間をとらなかったでしょう。

コンパイラ固有の拡張を使用する必要がないという特別な要件がない限り、必ず-Wpedantic-errorsを削除する必要があります。その場合、おそらくBoostを使用することはできません。 Boostが生成する警告を修正することはできないので、コードに関する真の警告を見つけるのが難しくなります。私は一般的に-Wall -Wextraできれいにコンパイルすることを目指しています。

+0

間違った推測;) – smallB

+0

gcc 4.6.1を使用していますか? – smallB

+0

はい。私のコマンドは 'g ++ - 4.6.1 -c test 'でした。cpp --std = C++ 0x'となり、エラーなしでコンパイルされます。ブーストディレクトリを指定しないで –

0

実際の問題はあなたのコードではありません。問題は、コンパイラのエラーメッセージが見つからないことです。あなたが他の何かをする前に、その問題を修正してください!

+0

とエラーメッセージが表示されていないことを伝えています! – smallB

+0

エラーが59件ありました。したがって、どこかに59のエラーメッセージがあります。あなたはどこで見つける必要があります。 – TonyK

+0

と記載されていないことを私はあなたに伝えています!私はあなたに何を言っているのか理解するのはどれくらい難しいですか? – smallB

0

端末内で正確なg++コマンドを実行します。エラーが表示されます。 IDEを使用しないでください。

関連する問題