Minor cleanup for string_view; mostly from suggestions by Richard Smith. Also, make the tests pass under c++03

llvm-svn: 212185
diff --git a/libcxx/include/experimental/string_view b/libcxx/include/experimental/string_view
index 77612af..a703940 100644
--- a/libcxx/include/experimental/string_view
+++ b/libcxx/include/experimental/string_view
@@ -223,11 +223,11 @@
         basic_string_view(const basic_string<_CharT, _Traits, _Allocator>& __str) _NOEXCEPT
             : __data (__str.data()), __size(__str.size()) {}
 
-        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
         basic_string_view(const _CharT* __s, size_type __len)
             : __data(__s), __size(__len)
         {
-            _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): recieved nullptr");
+//             _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): recieved nullptr");
         }
             
         _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
@@ -284,18 +284,16 @@
             return __data[__pos]; 
         }
 
-        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
         const_reference front() const
         {
-            _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty");
-            return __data[0];
+            return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0];
         }
         
-        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
         const_reference back() const
         {
-            _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty");
-            return __data[__size-1];
+            return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1];
         }
 
         _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
@@ -360,12 +358,15 @@
             return __rlen;
         }
         
-        _LIBCPP_CONSTEXPR_AFTER_CXX11 basic_string_view substr(size_type __pos = 0, size_type __n = npos) const
+        _LIBCPP_CONSTEXPR basic_string_view substr(size_type __pos = 0, size_type __n = npos) const
         {
-            if (__pos > size())
-                throw out_of_range("string_view::substr");
-            size_type __rlen = _VSTD::min( __n, size() - __pos );
-            return basic_string_view(data() + __pos, __rlen);
+//             if (__pos > size())
+//                 throw out_of_range("string_view::substr");
+//             size_type __rlen = _VSTD::min( __n, size() - __pos );
+//             return basic_string_view(data() + __pos, __rlen);
+			return __pos > size()
+			       ? throw out_of_range("string_view::substr")
+			       : basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos));
         }
 
         _LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT
@@ -377,32 +378,32 @@
             return __retval;
         }
         
-        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const
         {
             return substr(__pos1, __n1).compare(__sv);
         }
 
-        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         int compare(                       size_type __pos1, size_type __n1, 
                     basic_string_view _sv, size_type __pos2, size_type __n2) const
         {
             return substr(__pos1, __n1).compare(_sv.substr(__pos2, __n2));
         }
         
-        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         int compare(const _CharT* __s) const
         {
             return compare(basic_string_view(__s));
         }
         
-        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         int compare(size_type __pos1, size_type __n1, const _CharT* __s) const
         {
             return substr(__pos1, __n1).compare(basic_string_view(__s));
         }
         
-        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
+        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
         int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const
         {
             return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));
diff --git a/libcxx/test/experimental/string.view/string.view.access/back.pass.cpp b/libcxx/test/experimental/string.view/string.view.access/back.pass.cpp
index 2c644cd..093a858 100644
--- a/libcxx/test/experimental/string.view/string.view.access/back.pass.cpp
+++ b/libcxx/test/experimental/string.view/string.view.access/back.pass.cpp
@@ -38,7 +38,7 @@
     assert ( test ( U"a", 1 ));
 #endif
 
-#if _LIBCPP_STD_VER > 11
+#if __cplusplus >= 201103L
     {
     constexpr std::experimental::basic_string_view<char> sv ( "ABC", 2 );
     static_assert ( sv.length() ==  2,  "" );
diff --git a/libcxx/test/experimental/string.view/string.view.access/front.pass.cpp b/libcxx/test/experimental/string.view/string.view.access/front.pass.cpp
index f53dfb77..e9df44b 100644
--- a/libcxx/test/experimental/string.view/string.view.access/front.pass.cpp
+++ b/libcxx/test/experimental/string.view/string.view.access/front.pass.cpp
@@ -38,7 +38,7 @@
     assert ( test ( U"a", 1 ));
 #endif
 
-#if _LIBCPP_STD_VER > 11
+#if __cplusplus >= 201103L
     {
     constexpr std::experimental::basic_string_view<char> sv ( "ABC", 2 );
     static_assert ( sv.length() ==  2,  "" );
diff --git a/libcxx/test/experimental/string.view/string.view.capacity/capacity.pass.cpp b/libcxx/test/experimental/string.view/string.view.capacity/capacity.pass.cpp
index 6919be3..eb80216 100644
--- a/libcxx/test/experimental/string.view/string.view.capacity/capacity.pass.cpp
+++ b/libcxx/test/experimental/string.view/string.view.capacity/capacity.pass.cpp
@@ -53,10 +53,10 @@
 }
 
 int main () {
-    using string_view    = std::experimental::string_view;
-    using u16string_view = std::experimental::u16string_view;
-    using u32string_view = std::experimental::u32string_view;
-    using wstring_view   = std::experimental::wstring_view;
+    typedef std::experimental::string_view    string_view;
+    typedef std::experimental::u16string_view u16string_view;
+    typedef std::experimental::u32string_view u32string_view;
+    typedef std::experimental::wstring_view   wstring_view;
 
     test1<string_view> ();
     test1<u16string_view> ();
diff --git a/libcxx/test/experimental/string.view/string.view.cons/default.pass.cpp b/libcxx/test/experimental/string.view/string.view.cons/default.pass.cpp
index 4359fb6..e1d69f4 100644
--- a/libcxx/test/experimental/string.view/string.view.cons/default.pass.cpp
+++ b/libcxx/test/experimental/string.view/string.view.cons/default.pass.cpp
@@ -33,10 +33,10 @@
 }
 
 int main () {
-    using string_view    = std::experimental::string_view;
-    using u16string_view = std::experimental::u16string_view;
-    using u32string_view = std::experimental::u32string_view;
-    using wstring_view   = std::experimental::wstring_view;
+    typedef std::experimental::string_view    string_view;
+    typedef std::experimental::u16string_view u16string_view;
+    typedef std::experimental::u32string_view u32string_view;
+    typedef std::experimental::wstring_view   wstring_view;
 
     test<string_view> ();
     test<u16string_view> ();
diff --git a/libcxx/test/experimental/string.view/string.view.iterators/begin.pass.cpp b/libcxx/test/experimental/string.view/string.view.iterators/begin.pass.cpp
index 68fe597..07f3b36 100644
--- a/libcxx/test/experimental/string.view/string.view.iterators/begin.pass.cpp
+++ b/libcxx/test/experimental/string.view/string.view.iterators/begin.pass.cpp
@@ -40,10 +40,10 @@
 
 int main()
 {
-    using string_view    = std::experimental::string_view;
-    using u16string_view = std::experimental::u16string_view;
-    using u32string_view = std::experimental::u32string_view;
-    using wstring_view   = std::experimental::wstring_view;
+    typedef std::experimental::string_view    string_view;
+    typedef std::experimental::u16string_view u16string_view;
+    typedef std::experimental::u32string_view u32string_view;
+    typedef std::experimental::wstring_view   wstring_view;
 
     test(string_view   ());
     test(u16string_view());
diff --git a/libcxx/test/experimental/string.view/string.view.iterators/end.pass.cpp b/libcxx/test/experimental/string.view/string.view.iterators/end.pass.cpp
index 07028e7..2ed52b8 100644
--- a/libcxx/test/experimental/string.view/string.view.iterators/end.pass.cpp
+++ b/libcxx/test/experimental/string.view/string.view.iterators/end.pass.cpp
@@ -48,10 +48,10 @@
 
 int main()
 {
-    using string_view    = std::experimental::string_view;
-    using u16string_view = std::experimental::u16string_view;
-    using u32string_view = std::experimental::u32string_view;
-    using wstring_view   = std::experimental::wstring_view;
+    typedef std::experimental::string_view    string_view;
+    typedef std::experimental::u16string_view u16string_view;
+    typedef std::experimental::u32string_view u32string_view;
+    typedef std::experimental::wstring_view   wstring_view;
 
     test(string_view   ());
     test(u16string_view());
diff --git a/libcxx/test/experimental/string.view/string.view.iterators/rbegin.pass.cpp b/libcxx/test/experimental/string.view/string.view.iterators/rbegin.pass.cpp
index c5bf3c0..7d1c700 100644
--- a/libcxx/test/experimental/string.view/string.view.iterators/rbegin.pass.cpp
+++ b/libcxx/test/experimental/string.view/string.view.iterators/rbegin.pass.cpp
@@ -41,10 +41,10 @@
 
 int main()
 {
-    using string_view    = std::experimental::string_view;
-    using u16string_view = std::experimental::u16string_view;
-    using u32string_view = std::experimental::u32string_view;
-    using wstring_view   = std::experimental::wstring_view;
+    typedef std::experimental::string_view    string_view;
+    typedef std::experimental::u16string_view u16string_view;
+    typedef std::experimental::u32string_view u32string_view;
+    typedef std::experimental::wstring_view   wstring_view;
 
     test(string_view   ());
     test(u16string_view());
diff --git a/libcxx/test/experimental/string.view/string.view.iterators/rend.pass.cpp b/libcxx/test/experimental/string.view/string.view.iterators/rend.pass.cpp
index aa54883..57002f3 100644
--- a/libcxx/test/experimental/string.view/string.view.iterators/rend.pass.cpp
+++ b/libcxx/test/experimental/string.view/string.view.iterators/rend.pass.cpp
@@ -48,11 +48,11 @@
 
 int main()
 {
-    using string_view    = std::experimental::string_view;
-    using u16string_view = std::experimental::u16string_view;
-    using u32string_view = std::experimental::u32string_view;
-    using wstring_view   = std::experimental::wstring_view;
-
+    typedef std::experimental::string_view    string_view;
+    typedef std::experimental::u16string_view u16string_view;
+    typedef std::experimental::u32string_view u32string_view;
+    typedef std::experimental::wstring_view   wstring_view;
+    
     test(string_view   ());
     test(u16string_view());
     test(u32string_view());