Skip to content

Instantly share code, notes, and snippets.

@Lampo89
Last active June 28, 2021 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lampo89/8194726a0ee4f691baec47777ba3454c to your computer and use it in GitHub Desktop.
Save Lampo89/8194726a0ee4f691baec47777ba3454c to your computer and use it in GitHub Desktop.
// Type your code here, or load an example.
#include <algorithm>
#include <string>
#include <iostream>
#include <memory>
#include <utility>
using namespace std;
void increment(unique_ptr<int>&& p)
{
*p += 1;
cout << "integer is now " << *p << endl;
cout << "done" << endl;
}
void consume(unique_ptr<int> p)
{
*p += 4;
cout << "integer is now " << *p << endl;
cout << "done" << endl;
}
int main()
{
auto a = make_unique<int>(2);
increment(move(a));
cout << (a != nullptr ? "valid " : "moved") << endl;
consume(move(a));
cout << (a != nullptr ? "valid " : "moved") << endl;
cout << "before exit" << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment