I have following vector:
std::vector< std::pair< std::unique_ptr<CEdit>, CRect >> m_editCtrls;
I'm trying to insert here some data:
std::unique_ptr<CEdit> edit = std::make_unique<CEdit>();
CRect rectEdit;
//Init edit....
//1 - This doesn't work
std::pair< std::unique_ptr<CEdit>, CRect > pair = std::make_pair<std::unique_ptr<CEdit>, CRect>(std::move(edit), rectEdit);
//2 - This also
m_editCtrls.insert(std::make_pair(std::move(edit), rectEdit));
In first case I'm getting error - no instance of function template, in second - no instance of overloaded function.
Which is the proper way to insert this pointer into the vector?
Thank's for help.
Don't pass template arguments to std::make_pair. Just let them be deduced. See this video(link) by Steven Lavavej. (thanks to Passer By for finding the link)
std::pair<std::unique_ptr<CEdit>, CRect> pair = std::make_pair(std::move(edit), rectEdit);
std::vector does not have a function named insert that only takes one argument. You have to pass an iterator for a position. Perhaps you were looking for push_back?
m_editCtrls.push_back(std::make_pair(std::move(edit), rectEdit));
Or even better, emplace_back.
m_editCtrls.emplace_back(std::move(edit), rectEdit);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With