make_optional_explicit.pass.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // UNSUPPORTED: c++98, c++03, c++11, c++14
  10. // <optional>
  11. // template <class T, class... Args>
  12. // constexpr optional<T> make_optional(Args&&... args);
  13. #include <optional>
  14. #include <string>
  15. #include <memory>
  16. #include <cassert>
  17. int main()
  18. {
  19. using std::optional;
  20. using std::make_optional;
  21. {
  22. constexpr auto opt = make_optional<int>('a');
  23. static_assert(*opt == int('a'), "");
  24. }
  25. {
  26. std::string s("123");
  27. auto opt = make_optional<std::string>(s);
  28. assert(*opt == s);
  29. }
  30. {
  31. std::unique_ptr<int> s(new int(3));
  32. auto opt = make_optional<std::unique_ptr<int>>(std::move(s));
  33. assert(**opt == 3);
  34. assert(s == nullptr);
  35. }
  36. {
  37. auto opt = make_optional<std::string>(4, 'X');
  38. assert(*opt == "XXXX");
  39. }
  40. }