diff options
author | Ville Voutilainen <ville.voutilainen@gmail.com> | 2016-11-13 22:54:27 +0200 |
---|---|---|
committer | Ville Voutilainen <ville@gcc.gnu.org> | 2016-11-13 22:54:27 +0200 |
commit | 1701800580852987a23d00c45c3e0d1c30b095da (patch) | |
tree | 0c44d2f36ad4d9d5a494dbcdf9557fc3c380fee5 /libstdc++-v3/testsuite/21_strings/basic_string_view | |
parent | 975672f3573329b6ef9f687b706c566944a5887f (diff) | |
download | gcc-1701800580852987a23d00c45c3e0d1c30b095da.tar.gz |
Implement P0403R1, Literal suffixes for basic_string_view.
* include/std/string_view
(operator""sv(const char*, size_t)): New.
(operator""sv(const wchar_t*, size_t)): Likewise.
(operator""sv(const char16_t*, size_t)): Likewise.
(operator""sv(const char32_t*, size_t)): Likewise.
* testsuite/21_strings/basic_string_view/literals/types.cc: New.
* testsuite/21_strings/basic_string_view/literals/values.cc: Likewise.
* testsuite/experimental/string_view/literals/values.cc: Add
tests for literals with embedded NULs.
From-SVN: r242367
Diffstat (limited to 'libstdc++-v3/testsuite/21_strings/basic_string_view')
-rw-r--r-- | libstdc++-v3/testsuite/21_strings/basic_string_view/literals/types.cc | 45 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/21_strings/basic_string_view/literals/values.cc | 72 |
2 files changed, 117 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/literals/types.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/literals/types.cc new file mode 100644 index 00000000000..42e8b16070e --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/literals/types.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=gnu++17" } +// { dg-do compile } + +// Copyright (C) 2013-2016 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <string_view> +#include <type_traits> + +void +test01() +{ + using namespace std::literals::string_view_literals; + + static_assert(std::is_same<decltype("Hello"sv), std::string_view>::value, + "\"Hello\"s is std::string_view"); + + static_assert(std::is_same<decltype(u8"Hello"sv), std::string_view>::value, + "u8\"Hello\"s is std::string_view"); + +#ifdef _GLIBCXX_USE_WCHAR_T + static_assert(std::is_same<decltype(L"Hello"sv), std::wstring_view>::value, + "L\"Hello\"s is std::wstring_view"); +#endif + + static_assert(std::is_same<decltype(u"Hello"sv), std::u16string_view>::value, + "u\"Hello\"s is std::u16string_view"); + + static_assert(std::is_same<decltype(U"Hello"sv), std::u32string_view>::value, + "U\"Hello\"s is std::u32string_view"); +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/literals/values.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/literals/values.cc new file mode 100644 index 00000000000..bbaa70e854a --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/literals/values.cc @@ -0,0 +1,72 @@ +// { dg-options "-std=gnu++17" } + +// Copyright (C) 2013-2016 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <string_view> +#include <testsuite_hooks.h> + +void +test01() +{ + using namespace std::literals::string_view_literals; + + std::string_view planet = "Mercury"sv; +#ifdef _GLIBCXX_USE_WCHAR_T + std::wstring_view wplanet = L"Venus"sv; +#endif + std::string_view u8planet = u8"Mars"sv; + std::u16string_view u16planet = u"Jupiter"sv; + std::u32string_view u32planet = U"Saturn"sv; + + VERIFY( planet == std::string_view("Mercury") ); +#ifdef _GLIBCXX_USE_WCHAR_T + VERIFY( wplanet == std::wstring_view(L"Venus") ); +#endif + VERIFY( u8planet == std::string_view(u8"Mars") ); + VERIFY( u16planet == std::u16string_view(u"Jupiter") ); + VERIFY( u32planet == std::u32string_view(U"Saturn") ); +} + +void +test02() +{ + using namespace std::literals::string_view_literals; + + std::string_view planet_cratered = "Mercury\0cratered"sv; +#ifdef _GLIBCXX_USE_WCHAR_T + std::wstring_view wplanet_cratered = L"Venus\0cratered"sv; +#endif + std::string_view u8planet_cratered = u8"Mars\0cratered"sv; + std::u16string_view u16planet_cratered = u"Jupiter\0cratered"sv; + std::u32string_view u32planet_cratered = U"Saturn\0cratered"sv; + + VERIFY( planet_cratered == std::string_view("Mercury\0cratered", 16) ); +#ifdef _GLIBCXX_USE_WCHAR_T + VERIFY( wplanet_cratered == std::wstring_view(L"Venus\0cratered", 14) ); +#endif + VERIFY( u8planet_cratered == std::string_view(u8"Mars\0cratered", 13) ); + VERIFY( u16planet_cratered == std::u16string_view(u"Jupiter\0cratered", 16) ); + VERIFY( u32planet_cratered == std::u32string_view(U"Saturn\0cratered", 15) ); +} + +int +main() +{ + test01(); + test02(); +} |