Wednesday, 1 January 2020

C++ std::vector emplace vs insert

Emplace takes the arguments necessary to construct an object in place, whereas insert takes (a reference to) an object.



struct Foo
{
Foo(int n, double x);
};


std::vector v;
v.emplace(someIterator, 42, 3.1416);
v.insert(someIterator, Foo(42, 3.1416));

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...