string_view enhancements. Move to the correct namespace. Better constexpr support...
authorMarshall Clow <mclow.lists@gmail.com>
Tue, 8 Jul 2014 22:38:11 +0000 (22:38 +0000)
committerMarshall Clow <mclow.lists@gmail.com>
Tue, 8 Jul 2014 22:38:11 +0000 (22:38 +0000)
llvm-svn: 212569

libcxx/include/experimental/__config [new file with mode: 0644]
libcxx/include/experimental/string_view
libcxx/test/experimental/string.view/string.view.access/at.pass.cpp

diff --git a/libcxx/include/experimental/__config b/libcxx/include/experimental/__config
new file mode 100644 (file)
index 0000000..684a3b4
--- /dev/null
@@ -0,0 +1,24 @@
+// -*- C++ -*-
+//===--------------------------- __config ---------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP_EXPERIMENTAL_CONFIG
+#define _LIBCPP_EXPERIMENTAL_CONFIG
+
+#include <__config>
+
+#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace std { namespace experimental {
+#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL  } }
+#define _VSTD_EXPERIMENTAL std::experimental
+
+#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 {
+#define _LIBCPP_END_NAMESPACE_LFTS  } } }
+#define _VSTD_LFTS _VSTD_EXPERIMENTAL::fundamentals_v1
+
+#endif
index a703940..c38548b 100644 (file)
@@ -174,7 +174,7 @@ namespace std {
 
 */
 
-#include <__config>
+#include <experimental/__config>
 
 #include <string>
 #include <algorithm>
@@ -186,9 +186,7 @@ namespace std {
 #pragma GCC system_header
 #endif
 
-namespace std {
- namespace experimental {
-  inline namespace library_fundamentals_v1 {
+_LIBCPP_BEGIN_NAMESPACE_LFTS
     
     template<class _CharT, class _Traits = _VSTD::char_traits<_CharT> >
     class _LIBCPP_TYPE_VIS_ONLY basic_string_view {
@@ -276,12 +274,15 @@ namespace std {
         _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
         const_reference operator[](size_type __pos) const { return __data[__pos]; }
         
-        _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
+        _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
         const_reference at(size_type __pos) const
         {
-            if (__pos >= size())
-                throw out_of_range("string_view::at");
-            return __data[__pos]; 
+            return __pos >= size()
+                ? throw out_of_range("string_view::at")
+                : __data[__pos];
+//             if (__pos >= size())
+//                 throw out_of_range("string_view::at");
+//             return __data[__pos]; 
         }
 
         _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
@@ -358,7 +359,8 @@ namespace std {
             return __rlen;
         }
         
-        _LIBCPP_CONSTEXPR 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");
@@ -776,8 +778,7 @@ namespace std {
   typedef basic_string_view<char32_t> u32string_view;
   typedef basic_string_view<wchar_t>  wstring_view;
 
-}}}  // close std::experimental::library_fundamentals_v1
-
+_LIBCPP_END_NAMESPACE_LFTS
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 // [string.view.hash]
index 849a2a3..90c4ac8 100644 (file)
@@ -43,7 +43,7 @@ int main () {
     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,  "" );