[libcxx] r212185 - Minor cleanup for string_view; mostly from suggestions by Richard Smith. Also, make the tests pass under c++03
Marshall Clow
mclow.lists at gmail.com
Wed Jul 2 08:45:57 PDT 2014
Author: marshall
Date: Wed Jul 2 10:45:57 2014
New Revision: 212185
URL: http://llvm.org/viewvc/llvm-project?rev=212185&view=rev
Log:
Minor cleanup for string_view; mostly from suggestions by Richard Smith. Also, make the tests pass under c++03
Modified:
libcxx/trunk/include/experimental/string_view
libcxx/trunk/test/experimental/string.view/string.view.access/back.pass.cpp
libcxx/trunk/test/experimental/string.view/string.view.access/front.pass.cpp
libcxx/trunk/test/experimental/string.view/string.view.capacity/capacity.pass.cpp
libcxx/trunk/test/experimental/string.view/string.view.cons/default.pass.cpp
libcxx/trunk/test/experimental/string.view/string.view.iterators/begin.pass.cpp
libcxx/trunk/test/experimental/string.view/string.view.iterators/end.pass.cpp
libcxx/trunk/test/experimental/string.view/string.view.iterators/rbegin.pass.cpp
libcxx/trunk/test/experimental/string.view/string.view.iterators/rend.pass.cpp
Modified: libcxx/trunk/include/experimental/string_view
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/string_view?rev=212185&r1=212184&r2=212185&view=diff
==============================================================================
--- libcxx/trunk/include/experimental/string_view (original)
+++ libcxx/trunk/include/experimental/string_view Wed Jul 2 10:45:57 2014
@@ -223,11 +223,11 @@ namespace std {
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 @@ namespace std {
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 @@ namespace std {
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 @@ namespace std {
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));
Modified: libcxx/trunk/test/experimental/string.view/string.view.access/back.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/experimental/string.view/string.view.access/back.pass.cpp?rev=212185&r1=212184&r2=212185&view=diff
==============================================================================
--- libcxx/trunk/test/experimental/string.view/string.view.access/back.pass.cpp (original)
+++ libcxx/trunk/test/experimental/string.view/string.view.access/back.pass.cpp Wed Jul 2 10:45:57 2014
@@ -38,7 +38,7 @@ int main () {
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, "" );
Modified: libcxx/trunk/test/experimental/string.view/string.view.access/front.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/experimental/string.view/string.view.access/front.pass.cpp?rev=212185&r1=212184&r2=212185&view=diff
==============================================================================
--- libcxx/trunk/test/experimental/string.view/string.view.access/front.pass.cpp (original)
+++ libcxx/trunk/test/experimental/string.view/string.view.access/front.pass.cpp Wed Jul 2 10:45:57 2014
@@ -38,7 +38,7 @@ int main () {
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, "" );
Modified: libcxx/trunk/test/experimental/string.view/string.view.capacity/capacity.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/experimental/string.view/string.view.capacity/capacity.pass.cpp?rev=212185&r1=212184&r2=212185&view=diff
==============================================================================
--- libcxx/trunk/test/experimental/string.view/string.view.capacity/capacity.pass.cpp (original)
+++ libcxx/trunk/test/experimental/string.view/string.view.capacity/capacity.pass.cpp Wed Jul 2 10:45:57 2014
@@ -53,10 +53,10 @@ void test2 ( const CharT *s, size_t len
}
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> ();
Modified: libcxx/trunk/test/experimental/string.view/string.view.cons/default.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/experimental/string.view/string.view.cons/default.pass.cpp?rev=212185&r1=212184&r2=212185&view=diff
==============================================================================
--- libcxx/trunk/test/experimental/string.view/string.view.cons/default.pass.cpp (original)
+++ libcxx/trunk/test/experimental/string.view/string.view.cons/default.pass.cpp Wed Jul 2 10:45:57 2014
@@ -33,10 +33,10 @@ void test () {
}
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> ();
Modified: libcxx/trunk/test/experimental/string.view/string.view.iterators/begin.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/experimental/string.view/string.view.iterators/begin.pass.cpp?rev=212185&r1=212184&r2=212185&view=diff
==============================================================================
--- libcxx/trunk/test/experimental/string.view/string.view.iterators/begin.pass.cpp (original)
+++ libcxx/trunk/test/experimental/string.view/string.view.iterators/begin.pass.cpp Wed Jul 2 10:45:57 2014
@@ -40,10 +40,10 @@ test(S s)
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());
Modified: libcxx/trunk/test/experimental/string.view/string.view.iterators/end.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/experimental/string.view/string.view.iterators/end.pass.cpp?rev=212185&r1=212184&r2=212185&view=diff
==============================================================================
--- libcxx/trunk/test/experimental/string.view/string.view.iterators/end.pass.cpp (original)
+++ libcxx/trunk/test/experimental/string.view/string.view.iterators/end.pass.cpp Wed Jul 2 10:45:57 2014
@@ -48,10 +48,10 @@ test(S s)
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());
Modified: libcxx/trunk/test/experimental/string.view/string.view.iterators/rbegin.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/experimental/string.view/string.view.iterators/rbegin.pass.cpp?rev=212185&r1=212184&r2=212185&view=diff
==============================================================================
--- libcxx/trunk/test/experimental/string.view/string.view.iterators/rbegin.pass.cpp (original)
+++ libcxx/trunk/test/experimental/string.view/string.view.iterators/rbegin.pass.cpp Wed Jul 2 10:45:57 2014
@@ -41,10 +41,10 @@ test(S s)
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());
Modified: libcxx/trunk/test/experimental/string.view/string.view.iterators/rend.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/experimental/string.view/string.view.iterators/rend.pass.cpp?rev=212185&r1=212184&r2=212185&view=diff
==============================================================================
--- libcxx/trunk/test/experimental/string.view/string.view.iterators/rend.pass.cpp (original)
+++ libcxx/trunk/test/experimental/string.view/string.view.iterators/rend.pass.cpp Wed Jul 2 10:45:57 2014
@@ -48,11 +48,11 @@ test(S s)
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());
More information about the cfe-commits
mailing list