引数の constness と l(r)valueness を検出する関数を作成しました。
template<class T> std::string
detect(typename std::remove_reference<T>::type&&) {
return std::string(std::is_const<T>::value ? "const " : "") + "rvalue";
}
template<class T> std::string
detect(typename std::remove_reference<T>::type&) {
return std::string(std::is_const<T>::value ? "const " : "") + "lvalue";
}
何らかの理由で、is_const は const 型 (const int& など) でも常に false を返します。定数をキャプチャするために別のオーバーロードを追加してみました
template<class T> std::string
detect(const typename std::remove_reference<T>::type& ) { return "const lvalue"; }
コンパイラは、const int& に適用されると検出があいまいであると不平を言います。したがって、コンパイラは T=const int& を正しく計算していると思いますが、is_const が true を返さないのはなぜですか?