引数のconstとl(r)の高さを検出する関数を作成しました。いつもの例のconst int型&ため、constのタイプにも、falseを返しますis_const何らかの理由でC++ 11:完璧な転送でのconst
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";
}
、。私はconst性
template<class T> std::string
detect(const typename std::remove_reference<T>::type&) { return "const lvalue"; }
コンパイラは、その後のconst int型&に適用した場合に曖昧であることが検出文句キャプチャするために、別のオーバーロードを追加しようとしました。だから、私はコンパイラがT = const int &を正しいと理解していると思うが、なぜis_constはtrueを返さないのだろうか?
どのように 'detect'を呼びますか?パラメータの 'T 'は推論されていないコンテキストにあるため、明示的に指定する必要があります。 '(何か)を検出する'。どのような目的を破るか。 –
は、転送機能によって検出されます。 –