C++(11)<type_traits>
の使い方を理解しようとしています。私は、GCCは、テンプレートパラメータU
を推測できない理由見当もつかないテンプレート引数の種類C++での除算が失敗する11 <type_traits>
/home/per/f.cpp: In function ‘int main(int, const char**, const char**)’:
/home/per/f.cpp:15:23: error: no matching function for call to ‘add(unsigned int&, int&)’
auto a = add(ui, i);
^
/home/per/f.cpp:15:23: note: candidate is:
/home/per/f.cpp:5:10: note: template<class U, class S> U add(typename std::enable_if<std::is_unsigned<U>::value, U>::type, typename std::enable_if<std::is_signed<S>::value, S>::type)
inline U add(typename std::enable_if<std::is_unsigned<U>::value,U>::type a,
^
/home/per/f.cpp:5:10: note: template argument deduction/substitution failed:
/home/per/f.cpp:15:23: note: couldn't deduce template parameter ‘U’
auto a = add(ui, i);
^
としてGCC 4.8.1もエラーでコンパイルしたとき
は、ここに私の些細なテストプログラム
#include <type_traits>
template<class U, class S>
inline U add(typename std::enable_if<std::is_unsigned<U>::value,U>::type a,
typename std::enable_if<std::is_signed <S>::value,S>::type b)
{
return a + b;
}
int main(int argc, const char * argv[], const char * envp[])
{
unsigned int ui;
int i;
auto a = add(ui, i);
return 0;
}
です。誰も私のコードが欠けている情報を知っています。つまり、C++ 11で、符号なし整数型を第1引数として取り込み、整数型を第2引数として署名したプログラムを記述する方法はありますか?
あなたは '予選の左タイプをdecuceすることはできません::'。 –
** 14.8.2.5タイプ[temp.deduct.type]からのテンプレート引数の控除** 5推定されていないコンテキストは次のとおりです。 - 修飾IDを使用して指定されたタイプのネストされた名前の指定子。 – TemplateRex
すてきなコメントと回答ありがとう! –