That is true. But you want to yank a resource away from an object and give that resource to another one. That is not an optimal approach. With the way you're doing it, you'll be creating and recreating the resource every frame. You don't have to do that.
Otherwise, I don't know what you want to achieve.
Look at this code, encapsulation is maintained, no reallocations, no pointers, no references, no consts, no nothing. But it kinda smells, and what if I want swap multiple vectors, I need to pack a tuple.
bool Application::processWindowMessages()
{
// Temporary relinquish ownership of vector by passing it by rvalue to Window
m_windowMessages = m_Window->swapMessages(std::move(m_windowMessages));
for (auto& windowMessage : m_windowMessages)
{
UINT message = std::get<0>(windowMessage);
WPARAM wParam = std::get<1>(windowMessage);
LPARAM lParam = std::get<2>(windowMessage);
switch (message)
{
//...
// Handle messages
//...
}
}
return true
}
std::vector<std::tuple<UINT, WPARAM, LPARAM>>& Window::swapMessages(std::vector<std::tuple<UINT, WPARAM, LPARAM>>&& messages)
{
std::swap(messages, m_messages);
m_messages.resize(0);
return messages; // return by rvalue, giving back ownership
}