As far as I know std::list stores it's elements internally in a doubly linked list format which means heap memory is allocated. Suppose if I already have a variable that is heap allocated using new, can I instruct std ::list push_back() function to make use of this memory in it's internal doubly linked list instead of freshly allocating new memory and then copy the data into that new memory. This is a sample code:
#include <iostream>
#include <list>
struct St {
int a;
int b;
};
int main()
{
std::list<St> St_list;
St *st = new St;
st->a = 1;
st->b = 2;
St_list.push_back(*st); // can i instruct St_list to use the memory address of st
std::cout << st << std::endl;
std::cout << &St_list.back() << std::endl;
return 0;
}