decltype
的結果是否與模板標識符相同? (當談到T及其價值時,什麼是正確的術語?)。那是否存在斷言失敗的情況?是模板參數的decltype結果
template<typename T>
void foo(T x)
{
static_assert(std::is_same<decltype(x), T>::value, "decltype check failed");
}
decltype
的結果是否與模板標識符相同? (當談到T及其價值時,什麼是正確的術語?)。那是否存在斷言失敗的情況?是模板參數的decltype結果
template<typename T>
void foo(T x)
{
static_assert(std::is_same<decltype(x), T>::value, "decltype check failed");
}
變量類型x
是T,因此該static_assert總是要通過。
這可能會改變一些修改,例如'decltype((X))'? –
@MichaWiedenmann,確定:http://ideone.com/t06kJC –
對不起,我可以也應該自己檢查一下。我問的原因是因爲我認爲很難理解decltype和模板參數扣除的更細節。 –
「什麼是正確的術語?」 'T'是*模板參數*,其值是*模板參數*。 –