AntonBikineev updated this revision to Diff 78493.
AntonBikineev marked an inline comment as done.

https://reviews.llvm.org/D26830

Files:
  include/string_view
  test/std/strings/string.view/string.view.literals/literal.pass.cpp
  test/std/strings/string.view/string.view.literals/literal1.fail.cpp
  test/std/strings/string.view/string.view.literals/literal1.pass.cpp
  test/std/strings/string.view/string.view.literals/literal2.fail.cpp
  test/std/strings/string.view/string.view.literals/literal2.pass.cpp
  test/std/strings/string.view/string.view.literals/literal3.pass.cpp

Index: test/std/strings/string.view/string.view.literals/literal3.pass.cpp
===================================================================
--- /dev/null
+++ test/std/strings/string.view/string.view.literals/literal3.pass.cpp
@@ -0,0 +1,21 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include <string_view>
+#include <cassert>
+
+int main()
+{
+    using namespace std;
+
+    string_view foo  =   ""sv;
+}
Index: test/std/strings/string.view/string.view.literals/literal2.pass.cpp
===================================================================
--- /dev/null
+++ test/std/strings/string.view/string.view.literals/literal2.pass.cpp
@@ -0,0 +1,21 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include <string_view>
+#include <cassert>
+
+int main()
+{
+    using namespace std::literals::string_view_literals;
+
+    std::string_view foo  =   ""sv;
+}
Index: test/std/strings/string.view/string.view.literals/literal2.fail.cpp
===================================================================
--- /dev/null
+++ test/std/strings/string.view/string.view.literals/literal2.fail.cpp
@@ -0,0 +1,19 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include <string_view>
+#include <cassert>
+
+int main()
+{
+    std::string_view foo  =   ""sv;  // should fail w/conversion operator not found
+}
Index: test/std/strings/string.view/string.view.literals/literal1.pass.cpp
===================================================================
--- /dev/null
+++ test/std/strings/string.view/string.view.literals/literal1.pass.cpp
@@ -0,0 +1,21 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include <string_view>
+#include <cassert>
+
+int main()
+{
+    using namespace std::literals;
+
+    std::string_view foo  =   ""sv;
+}
Index: test/std/strings/string.view/string.view.literals/literal1.fail.cpp
===================================================================
--- /dev/null
+++ test/std/strings/string.view/string.view.literals/literal1.fail.cpp
@@ -0,0 +1,21 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include <string_view>
+#include <cassert>
+
+int main()
+{
+    using std::string_view;
+
+    string_view foo  =   ""sv;  // should fail w/conversion operator not found
+}
Index: test/std/strings/string.view/string.view.literals/literal.pass.cpp
===================================================================
--- /dev/null
+++ test/std/strings/string.view/string.view.literals/literal.pass.cpp
@@ -0,0 +1,45 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include <string>
+#include <string_view>
+#include <cassert>
+
+int main()
+{
+    using namespace std::literals::string_view_literals;
+
+    static_assert ( std::is_same<decltype(   "Hi"sv), std::string_view>::value, "" );
+    static_assert ( std::is_same<decltype(  L"Hi"sv), std::wstring_view>::value, "" );
+    static_assert ( std::is_same<decltype(  u"Hi"sv), std::u16string_view>::value, "" );
+    static_assert ( std::is_same<decltype(  U"Hi"sv), std::u32string_view>::value, "" );
+
+    std::string_view foo;
+    std::wstring_view Lfoo;
+    std::u16string_view ufoo;
+    std::u32string_view Ufoo;
+
+    foo  =   ""sv;     assert( foo.size() == 0);
+    Lfoo =  L""sv;     assert(Lfoo.size() == 0);
+    ufoo =  u""sv;     assert(ufoo.size() == 0);
+    Ufoo =  U""sv;     assert(Ufoo.size() == 0);
+
+    foo  =   " "sv;     assert( foo.size() == 1);
+    Lfoo =  L" "sv;     assert(Lfoo.size() == 1);
+    ufoo =  u" "sv;     assert(ufoo.size() == 1);
+    Ufoo =  U" "sv;     assert(Ufoo.size() == 1);
+
+    foo  =   "ABC"sv;     assert( foo ==   "ABC");   assert( foo == std::string   (  "ABC"));
+    Lfoo =  L"ABC"sv;     assert(Lfoo ==  L"ABC");   assert(Lfoo == std::wstring  ( L"ABC"));
+    ufoo =  u"ABC"sv;     assert(ufoo ==  u"ABC");   assert(ufoo == std::u16string( u"ABC"));
+    Ufoo =  U"ABC"sv;     assert(Ufoo ==  U"ABC");   assert(Ufoo == std::u32string( U"ABC"));
+}
Index: include/string_view
===================================================================
--- include/string_view
+++ include/string_view
@@ -746,6 +746,36 @@
     return __do_string_hash(__val.data(), __val.data() + __val.size());
 }
 
+inline namespace literals
+{
+  inline namespace string_view_literals
+  {
+    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+    string_view operator "" sv(const char* __str, size_t __len) _NOEXCEPT
+    {
+        return string_view(__str, __len);
+    }
+
+    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+    u16string_view operator "" sv(const char16_t* __str, size_t __len) _NOEXCEPT
+    {
+        return u16string_view(__str, __len);
+    }
+
+    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+    u32string_view operator "" sv(const char32_t* __str, size_t __len) _NOEXCEPT
+    {
+        return u32string_view(__str, __len);
+    }
+
+    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+    wstring_view operator "" sv(const wchar_t* __str, size_t __len) _NOEXCEPT
+    {
+        return wstring_view(__str, __len);
+    }
+  } // namespace string_view_literals
+} // namespace literals
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif // _LIBCPP_STRING_VIEW
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to