Questions tagged [emplace]

For questions that concern constructing objects directly within some container object, as opposed to copying/moving the object into the container.

Use for questions related to the act of doing something in place, like for example inserting a new element in place.

For example, for an std::vector in , one could use std:emplace_back(), which is described like:

Inserts 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 constructor.

183 questions
-2
votes
1 answer

vector emplace back, uniqure ptrs, raw ptrs and memory leak

I read one answer about using std::vector::emplace_back on std::vector> and getting memory leaks when passing raw pointers (my_vec.emplace_back(new SomeClass())) in some exceptional scenario. Since that post is old (2016)…
kiner_shah
  • 3,939
  • 7
  • 23
  • 37
-2
votes
1 answer

"expression cannot be used as a function" in return statement

Code (also screenshot): /*** Attempts to emplace new_vert in vertices, returning false if it failed (i.e., the vertex was already in vertices) or true if it succeeded ***/ template bool Graph::addVert(const T&…
-5
votes
2 answers

vector emplace_back usage (C++11) of containing another vector (partial vector)

Has anyone known related reference for such emplace_back usage (C++11)? void func(const vector &A){ vector > B; B.emplace_back(A.cbegin() , A.cend()); // emplace vector A directly }
HaoZ
  • 39
  • 1
  • 7
1 2 3
12
13