1770 次
2 に答える
1
まず第一に、これ:
remove_reference<unique_ptr<int>&>::type
これと同等です:
unique_ptr<int>
そこの必要性がわかりませんremove_reference
。自分を納得させるには、次のことを試してください。
#include <type_traits>
#include <memory>
static_assert(std::is_same<
remove_reference<unique_ptr<int>&>::type,
unique_ptr<int>>::value, "!");
そして、アサーションが起動しないことがわかります ( live example )。
発生しているコンパイラ エラーの理由として最も可能性が高いのはtypename
、関数テンプレートで明確化ツールを使用していないことです。
template<typename K, typename V, typename M>
void moveValueForUniqueKey(M targetMap, K key,
typename remove_reference<unique_ptr<V>&>::type value) throw(char)
// ^^^^^^^^
{
// ...
}
しかし、繰り返しますが、そこで使用する理由はありませんremove_reference
:
template<typename K, typename V, typename M>
void moveValueForUniqueKey(M targetMap, K key, unique_ptr<V> value) throw(char)
// ^^^^^^^^^^^^^
{
// ...
}
最後に、動的例外指定は C++11 では非推奨であることに注意してください。
于 2013-06-05T21:48:03.763 に答える