18

型特性は、次のようなケースを処理std::vector < std::unique_ptr <int> >し、それがコピー構築可能でないことを検出できる必要がありますか?

https://ideone.com/gbcRUaの例を次に示します(g++ 4.8.1 を実行)

#include <type_traits>
#include <vector>
#include <iostream>
#include <memory>

int main()
{
    // This prints 1, implying that it's copy constructible, when it's clearly not
    std::cout << std::is_copy_constructible< std::vector<std::unique_ptr<int> > >::value << std::endl; 
    return 0;
}

これが の正しい動作である場合is_copy_constructible、コピーの構成が不適切であることを検出する方法はありますか? まあ、コンパイルに失敗するだけではありません。

4

2 に答える 2

2

C++11 標準の表 49 には、クラスがis_copy_constructable<T>::valuetrue になるために満たす必要がある条件がリストされていますが、残念ながらそれほど多くはありません。

is_constructable<T, const T&>::valuetrue

したがってstd::vector<T>、コピー コンストラクターがある場合は、テストに合格します。

于 2013-08-23T13:50:39.387 に答える