make_unique.single.pass.cpp 957 B

1234567891011121314151617181920212223242526272829303132333435
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // UNSUPPORTED: c++98, c++03, c++11
  9. #include <memory>
  10. #include <string>
  11. #include <cassert>
  12. #include "test_macros.h"
  13. int main(int, char**)
  14. {
  15. {
  16. std::unique_ptr<int> p1 = std::make_unique<int>(1);
  17. assert ( *p1 == 1 );
  18. p1 = std::make_unique<int> ();
  19. assert ( *p1 == 0 );
  20. }
  21. {
  22. std::unique_ptr<std::string> p2 = std::make_unique<std::string> ( "Meow!" );
  23. assert ( *p2 == "Meow!" );
  24. p2 = std::make_unique<std::string> ();
  25. assert ( *p2 == "" );
  26. p2 = std::make_unique<std::string> ( 6, 'z' );
  27. assert ( *p2 == "zzzzzz" );
  28. }
  29. return 0;
  30. }