1.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // { dg-options "-std=gnu++17" }
  2. // Copyright (C) 2013-2022 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License along
  14. // with this library; see the file COPYING3. If not see
  15. // <http://www.gnu.org/licenses/>.
  16. // basic_string_view constructors.
  17. namespace cons_1 {
  18. static void
  19. test01 ()
  20. {
  21. typedef gdb::string_view::size_type csize_type;
  22. // basic_string_view()
  23. const gdb::string_view str00{};
  24. VERIFY( str00.length() == 0 );
  25. VERIFY( str00.data() == nullptr );
  26. // basic_string_view(const char*)
  27. const char str_lit01[] = "rodeo beach, marin";
  28. const gdb::string_view str01{str_lit01};
  29. VERIFY( str01.length() == 18 );
  30. VERIFY( str01.data() == str_lit01 );
  31. const gdb::string_view str02{"baker beach, san francisco"};
  32. VERIFY( str02.length() == 26 );
  33. // basic_string_view(const string_view&)
  34. gdb::string_view str04{str01};
  35. VERIFY( str04.length() == str01.length() );
  36. VERIFY( str04.data() == str01.data() );
  37. // basic_string_view(const char* s)
  38. csize_type len_lit01 = strlen(str_lit01);
  39. gdb::string_view str05{str_lit01, len_lit01};
  40. VERIFY( str05.length() == len_lit01 );
  41. VERIFY( str05.data() == str_lit01 );
  42. // basic_string_view(basic_string& s)
  43. std::string istr07(10, 'z');
  44. gdb::string_view str07{istr07};
  45. VERIFY( str07.length() == 10 );
  46. }
  47. static int
  48. main ()
  49. {
  50. test01();
  51. return 0;
  52. }
  53. } // namespace cons_1