What exactly are the rules for copy elision when one is using auto and commits to a specific type ? (see: GotW - Almost always auto).
From my understanding, the move/copy constructor is required to be accessible even though it's not generally used. But then what's the difference between unique_ptr and fstream in the example below ? (something to do with 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"};
// ^ ~~~~~~~~~~~~~~~~~~~~
Aucun commentaire:
Enregistrer un commentaire