Vector of streams in C++11
c++, c++11, standards, stream, vector
Solution
If you scroll down to the end of the errors thrown by clang you'll see this one:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/basic_ios.h:66:23: note: copy constructor of 'basic_ios<char, std::char_traits<char> >' is implicitly deleted because base class 'std::ios_base' has an inaccessible copy constructor
This is the corresponding line from gcc's long list of errors:
/usr/include/c++/4.8/bits/basic_ios.h:66:11: note: 'std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)' is implicitly deleted because the default definition would be ill-formed:
class basic_ios : public ios_base
This is because libstdc++ is missing move constructors for `basic_ios`, as listed here on the status page.
27.5 | Iostreams base classes | Partial | Missing move and swap operations on `basic_ios`.
And here's the associated bugzilla. Your code compiles with clang if you use libc++.
A simpler example, copied from the bug report, also fails to compile:
#include <sstream>
#include <utility>
std::stringstream getss(){
std::stringstream q;
return std::move(q);
}
Problem
The following code ``` vector<ofstream> v; v.emplace_back("file1.txt"); v.emplace_back("file2.txt"); for (int i = 0, ilen = v.size(); i < ilen; ++i) v[i] << "Test" << i << endl; ``` compiles fine in VS2013, but fails in GCC with unreadable message. It seems that the behaviour of VS2013 is correct. - I don't copy a stream, but create it in-place; - When `vector` gets big enough, contents should be moved to a new memory area. Though I couldn't find a right place in standard that says something articulate on this. Could someone quote it, please?