下面的函數對所有的算術類型定義:如何理解提振下使用:: enable_if和boost :: disable_if
template <class T>
typename enable_if_c<boost::is_arithmetic<T>::value, T>::type
foo(T t) { return t; }
問題1>什麼是價值意思嗎?爲什麼不簡單使用boost::is_arithmetic<T>
?
boost::is_arithmetic<T>::value
問2>是否type
意味着T
?
問題3>是真的,boost::is_arithmetic<T>::value
只用於過濾非算術和功能,實際上只需要T
?
問題4>如何閱讀以下說明?
template <typename T>
void dodah(T i, typename disable_if<is_integral<T> >::type* p=0)
{
cout << "I: " << i << endl;
}
莫非1>禁用整體式2>只接受非整數型和已埋入型如type
?
謝謝