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
0
votes
1 answer

unordered_map emplace compile error

I have the following code in myclass.h file: typedef std::unordered_set< int, int> Parameters; class MyClass { public: void myFunction(); private: Parameters* m_params; } Then, myFunction looks as follows: void…
omniyo
  • 330
  • 2
  • 6
  • 19
0
votes
1 answer

priority_queue emplace gives segmentation fault

The following code gives segmentation fault, could someone enlighten me? All I wanted to achieve is to have a priority queue sorted with ascending order of tv.t or descending order of tv.m. struct tv { int m; int c; int t; tv(int mm,…
Monster Hunter
  • 846
  • 1
  • 12
  • 24
0
votes
2 answers

Is sqlite database creted on both server and client's device?

i have recently update my website files to my server.but my sqlite database have been createad on the server,but i wanted it to be on the visitor's device. I tought that sqlite was used for offline purpose for websites, i'm a little bit confused…
Mahamadou Taibou
  • 155
  • 1
  • 1
  • 15
0
votes
2 answers

Custom Container emplace with variadic templates

I am implementing a simple circular vector class. I want to implement an emplace member function, but I am getting an error which I don't understand. It might be a simple fix for something I am doing wrong, but since I don't have much experience…
Miguel Mesquita Alfaiate
  • 2,851
  • 5
  • 30
  • 56
0
votes
1 answer

emplace_back calls assignment operator in vectors but not in list

As per http://www.cplusplus.com/reference/vector/vector/emplace_back/ I understood that emplace_back would create objects in place without calling the assignment operator . But in case of std::vector they call the assignment operator and they donot…
Cpp crusaders
  • 117
  • 2
  • 10
0
votes
1 answer

priority_queue::emplace calls push_heap?

According to CPP Reference, std::priority_queue::emplace "effectively calls" c.emplace_back(std::forward(args)...); std::push_heap(c.begin(), c.end(), comp); What does "effectively" mean here? Does it mean emplace has the same…
Agrim Pathak
  • 3,047
  • 4
  • 27
  • 43
0
votes
3 answers

C++11 segfault on reference to unordered_map in vector

When i run the following code I get a segfault on the 'find()' call. #include #include struct item { std::unordered_map map; }; int main(int argc, char** argv) { std::vector stack; …
Jeremy Salwen
  • 8,061
  • 5
  • 50
  • 73
0
votes
1 answer

3D Vector of struct emplace_back

This isn't working. And the reason why is cryptic to me. PS: Using C++11 http://ideone.com/elopRc #include #include #include using namespace std; int main() { struct MyStruct { size_t some_num; …
ParoX
  • 5,685
  • 23
  • 81
  • 152
-1
votes
1 answer

Why emplacing back into vector does not work with copy semantics disabled via inheritance

I am trying to find out why in the following example, when I disable copy-semantics but preserve move-semantics, emplacing into std::vector works in one case but does not work in another (when inheritance is used): #include #include…
Enmaniac
  • 19
  • 3
-1
votes
1 answer

Problem understanding the behaviour of std::map try_emplace for a composite key

I have a std::map, where CompositeKey is a class I wrote. This CompositeKey has three int data members, all the constructors, all the copy assignment operators and a friend bool operator<, which compares the sum of the…
vaeVictis
  • 484
  • 1
  • 3
  • 13
-1
votes
1 answer

Equivalent for emplace and reserve functions in C program

I am trying to convert the following piece of code from C++ to C. I created an array, but I'm not sure what can be a precise replacement for emplace() and reserve() and for size_t, what can be done in this case? template Student(float…
P Pp
  • 137
  • 1
  • 6
-1
votes
1 answer

Why can't emplace accept begin and end as parameter

I'm developing a basic(low-level) c++11 library for my team. Now I'm trying to develop a custom container. template class CustomMap { public: void insert(const std::map& container) {…
Yves
  • 11,597
  • 17
  • 83
  • 180
-1
votes
1 answer

C++ better way to emplace char* strings into a std::vector?

I am populating a string vector from any of char[] char* std::string by emplacing them in the std::vector This code works but is a bit clunky looking and takes three templates to cover variadics and initializer lists. Is there a more canonical idiom…
Chris Reid
  • 460
  • 4
  • 9
-1
votes
1 answer

Making map double pair

I have class: template class CRoute { public: CRoute& Add(const _T & u1 , const _T & u2 , const _E & e); ... private: map < _T, vector> > graf; }; Add function have to assign elements to…
Dmitriy
  • 77
  • 1
  • 1
  • 5
-1
votes
1 answer

Assigning a vector element to result of function that invokes emplace_back?

The test method on the following class does not have the effect I would expect it to. I have a suspicion it is something to do with the fact that the invocation of emplace_back somehow invalidates the reference obtained via the subscript. Either way…
Edward J Brown
  • 333
  • 1
  • 5
  • 17
1 2 3
12
13