Monday, 11 April 2016

c++ - Why can't I emplace ifstreams in a vector?



The following example program doesn't compile for me on either
clang 3.1 or gcc 4.8:



#include 

#include

using namespace std;

int main()
{
vector bla;
bla.emplace_back("filename");
return 0;
}



However, I thought emplace_back should




"Insert a new element at the end of the vector, right after its
current last element. This new element is constructed in place using
args as the arguments for its construction."





Does anyone know why this doesn't compile then? did I misunderstand or are the library implementations not yet complete?


Answer



Streams in c++11 are movable, so in theory you should be able to do what you want, problem is that movable streams have not yet been implemented in gcc/libstdc++.



To back up my answer further please take a look at gcc/libstdc++ c++11 status:
http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011



Especially 27.5, 27.8, 27.9


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...