fork download
  1. #include <iostream>
  2. #include <memory>
  3. using namespace std;
  4.  
  5. int main() {
  6. auto pstr = make_unique<string>(5, '*');
  7. cout << (pstr ? *pstr : "pstr is empty") << endl;
  8. unique_ptr<string> pstr2(pstr.release());
  9. // or: decltype(pstr) pstr2(pstr.release());
  10. cout << (pstr ? *pstr : "pstr is empty") << endl;
  11. cout << (pstr2 ? *pstr2 : "pstr2 is empty") << endl;
  12. auto pstr3(move(pstr2));
  13. // or: decltype(pstr2) pstr3(move(pstr2));
  14. cout << (pstr2 ? *pstr2 : "pstr2 is empty") << endl;
  15. cout << (pstr3 ? *pstr3 : "pstr3 is empty") << endl;
  16. return 0;
  17. }
Success #stdin #stdout 0s 4416KB
stdin
Standard input is empty
stdout
*****
pstr is empty
*****
pstr2 is empty
*****