Skip to content

Instantly share code, notes, and snippets.

@apivovarov
Created September 19, 2023 23:38
Show Gist options
  • Save apivovarov/b192a8ec73a24925b5b0fa000f4e63be to your computer and use it in GitHub Desktop.
Save apivovarov/b192a8ec73a24925b5b0fa000f4e63be to your computer and use it in GitHub Desktop.
NRVO Test
#include <iostream>
#include <vector>
std::vector<int> testNRVO(int value, size_t size, const std::vector<int> **localVec)
{
std::vector<int> vec(size, value);
*localVec = &vec;
/* Do something here.. */
return vec;
}
int main()
{
const std::vector<int> *localVec = nullptr;
std::vector<int> vec = testNRVO(0, 10, &localVec);
if (&vec == localVec)
std::cout << "NRVO was applied" << std::endl;
else
std::cout << "NRVO was not applied" << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment