implicit_deduction_guides.pass.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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, c++14
  9. // UNSUPPORTED: libcpp-no-deduction-guides
  10. // <string_view>
  11. // Test that the constructors offered by std::basic_string_view are formulated
  12. // so they're compatible with implicit deduction guides.
  13. #include <string_view>
  14. #include <cassert>
  15. #include "test_macros.h"
  16. #include "constexpr_char_traits.h"
  17. // Overloads
  18. // ---------------
  19. // (1) basic_string_view() - NOT TESTED
  20. // (2) basic_string_view(const basic_string_view&)
  21. // (3) basic_string_view(const CharT*, size_type)
  22. // (4) basic_string_view(const CharT*)
  23. int main(int, char**)
  24. {
  25. { // Testing (1)
  26. // Nothing TODO. Cannot deduce without any arguments.
  27. }
  28. { // Testing (2)
  29. const std::string_view sin("abc");
  30. std::basic_string_view s(sin);
  31. ASSERT_SAME_TYPE(decltype(s), std::string_view);
  32. assert(s == "abc");
  33. using WSV = std::basic_string_view<wchar_t, constexpr_char_traits<wchar_t>>;
  34. const WSV win(L"abcdef");
  35. std::basic_string_view w(win);
  36. ASSERT_SAME_TYPE(decltype(w), WSV);
  37. assert(w == L"abcdef");
  38. }
  39. { // Testing (3)
  40. std::basic_string_view s("abc", 2);
  41. ASSERT_SAME_TYPE(decltype(s), std::string_view);
  42. assert(s == "ab");
  43. std::basic_string_view w(L"abcdef", 4);
  44. ASSERT_SAME_TYPE(decltype(w), std::wstring_view);
  45. assert(w == L"abcd");
  46. }
  47. { // Testing (4)
  48. std::basic_string_view s("abc");
  49. ASSERT_SAME_TYPE(decltype(s), std::string_view);
  50. assert(s == "abc");
  51. std::basic_string_view w(L"abcdef");
  52. ASSERT_SAME_TYPE(decltype(w), std::wstring_view);
  53. assert(w == L"abcdef");
  54. }
  55. return 0;
  56. }