Last active
June 28, 2021 20:15
-
-
Save Lampo89/8194726a0ee4f691baec47777ba3454c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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