c – 自动和复制省略
当使用auto并提交到特定类型时,复制省略的规则究竟是什么? (见:GotW – Almost always auto).
根据我的理解,移动/复制构造函数必须是可访问的,即使它通常不被使用.但是接下来的例子中unique_ptr和fstream之间的区别是什么? (与noexcept有关吗?)
#include <memory>
#include <fstream>
int main()
{
auto f = std::fstream{"foo.bar"};
auto i = std::unique_ptr<int>{new int};
return 0;
}
// main.cc:6:10: error: call to implicitly-deleted copy constructor of 'std::basic_fstream<char>'
// auto f = std::fstream{"foo.bar"};
// ^ ~~~~~~~~~~~~~~~~~~~~