[libcxx] r210561 - Make the helper routines in string really be constexpr. This required a bit of refacoring in algorithm as well. Give them better names while we're at it. All of these are internal rotines; no visible functionality change.
Marshall Clow
mclow.lists at gmail.com
Tue Jun 10 11:51:56 PDT 2014
Author: marshall
Date: Tue Jun 10 13:51:55 2014
New Revision: 210561
URL: http://llvm.org/viewvc/llvm-project?rev=210561&view=rev
Log:
Make the helper routines in string really be constexpr. This required a bit of refacoring in algorithm as well. Give them better names while we're at it. All of these are internal rotines; no visible functionality change.
Modified:
libcxx/trunk/include/algorithm
libcxx/trunk/include/string
Modified: libcxx/trunk/include/algorithm
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=210561&r1=210560&r2=210561&view=diff
==============================================================================
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Tue Jun 10 13:51:55 2014
@@ -975,7 +975,7 @@ __find_end(_BidirectionalIterator1 __fir
}
template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
-_RandomAccessIterator1
+_LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator1
__find_end(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
_RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
random_access_iterator_tag, random_access_iterator_tag)
@@ -1041,8 +1041,8 @@ find_end(_ForwardIterator1 __first1, _Fo
// find_first_of
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-_ForwardIterator1
-find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+_LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator1
+__find_first_of_ce(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred)
{
for (; __first1 != __last1; ++__first1)
@@ -1052,6 +1052,16 @@ find_first_of(_ForwardIterator1 __first1
return __last1;
}
+
+template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
+inline _LIBCPP_INLINE_VISIBILITY
+_ForwardIterator1
+find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+ _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred)
+{
+ return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred);
+}
+
template <class _ForwardIterator1, class _ForwardIterator2>
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator1
@@ -1060,7 +1070,7 @@ find_first_of(_ForwardIterator1 __first1
{
typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
- return _VSTD::find_first_of(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
+ return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
}
// adjacent_find
@@ -1440,7 +1450,7 @@ __search(_ForwardIterator1 __first1, _Fo
}
template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
-_RandomAccessIterator1
+_LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator1
__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
_RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
random_access_iterator_tag, random_access_iterator_tag)
Modified: libcxx/trunk/include/string
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=210561&r1=210560&r2=210561&view=diff
==============================================================================
--- libcxx/trunk/include/string (original)
+++ libcxx/trunk/include/string Tue Jun 10 13:51:55 2014
@@ -990,10 +990,10 @@ char_traits<char32_t>::assign(char_type*
// helper fns for basic_string
-// __find
+// __str_find
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-__find(const _CharT *__p, _SizeT __sz,
+__str_find(const _CharT *__p, _SizeT __sz,
_CharT __c, _SizeT __pos) _NOEXCEPT
{
if (__pos >= __sz)
@@ -1006,28 +1006,28 @@ __find(const _CharT *__p, _SizeT __sz,
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-__find(const _CharT *__p, _SizeT __sz,
+__str_find(const _CharT *__p, _SizeT __sz,
const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
{
if (__pos > __sz || __sz - __pos < __n)
return __npos;
if (__n == 0)
return __pos;
-// if (__n == 1)
-// return _VSTD::__find<_CharT, _SizeT, _Traits, __npos>(__p, __sz, *__s, __pos);
const _CharT* __r =
- _VSTD::search(__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq);
+ _VSTD::__search(__p + __pos, __p + __sz,
+ __s, __s + __n, _Traits::eq,
+ random_access_iterator_tag(), random_access_iterator_tag());
if (__r == __p + __sz)
return __npos;
return static_cast<_SizeT>(__r - __p);
}
-// __rfind
+// __str_rfind
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-__rfind(const _CharT *__p, _SizeT __sz,
+__str_rfind(const _CharT *__p, _SizeT __sz,
_CharT __c, _SizeT __pos) _NOEXCEPT
{
if (__sz < 1)
@@ -1046,7 +1046,7 @@ __rfind(const _CharT *__p, _SizeT __sz,
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-__rfind(const _CharT *__p, _SizeT __sz,
+__str_rfind(const _CharT *__p, _SizeT __sz,
const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
{
__pos = _VSTD::min(__pos, __sz);
@@ -1054,21 +1054,23 @@ __rfind(const _CharT *__p, _SizeT __sz,
__pos += __n;
else
__pos = __sz;
- const _CharT* __r = _VSTD::find_end(__p, __p + __pos, __s, __s + __n, _Traits::eq);
+ const _CharT* __r = _VSTD::__find_end(
+ __p, __p + __pos, __s, __s + __n, _Traits::eq,
+ random_access_iterator_tag(), random_access_iterator_tag());
if (__n > 0 && __r == __p + __pos)
return __npos;
return static_cast<_SizeT>(__r - __p);
}
-// __find_first_of
+// __str_find_first_of
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-__find_first_of(const _CharT *__p, _SizeT __sz,
+__str_find_first_of(const _CharT *__p, _SizeT __sz,
const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
{
if (__pos >= __sz || __n == 0)
return __npos;
- const _CharT* __r = _VSTD::find_first_of
+ const _CharT* __r = _VSTD::__find_first_of_ce
(__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );
if (__r == __p + __sz)
return __npos;
@@ -1076,10 +1078,10 @@ __find_first_of(const _CharT *__p, _Size
}
-// __find_last_of
+// __str_find_last_of
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-__find_last_of(const _CharT *__p, _SizeT __sz,
+__str_find_last_of(const _CharT *__p, _SizeT __sz,
const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
{
if (__n != 0)
@@ -1099,10 +1101,10 @@ __find_last_of(const _CharT *__p, _SizeT
}
-// __find_first_not_of
+// __str_find_first_not_of
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-__find_first_not_of(const _CharT *__p, _SizeT __sz,
+__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
{
if (__pos < __sz)
@@ -1118,7 +1120,7 @@ __find_first_not_of(const _CharT *__p, _
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-__find_first_not_of(const _CharT *__p, _SizeT __sz,
+__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
_CharT __c, _SizeT __pos) _NOEXCEPT
{
if (__pos < __sz)
@@ -1132,10 +1134,10 @@ __find_first_not_of(const _CharT *__p, _
}
-// __find_last_not_of
+// __str_find_last_not_of
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-__find_last_not_of(const _CharT *__p, _SizeT __sz,
+__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
{
if (__pos < __sz)
@@ -1151,7 +1153,7 @@ __find_last_not_of(const _CharT *__p, _S
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
-__find_last_not_of(const _CharT *__p, _SizeT __sz,
+__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
_CharT __c, _SizeT __pos) _NOEXCEPT
{
if (__pos < __sz)
@@ -3427,7 +3429,7 @@ basic_string<_CharT, _Traits, _Allocator
size_type __n) const _NOEXCEPT
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
- return _VSTD::__find<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
@@ -3437,7 +3439,7 @@ typename basic_string<_CharT, _Traits, _
basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
size_type __pos) const _NOEXCEPT
{
- return _VSTD::__find<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find<value_type, size_type, traits_type, npos>
(data(), size(), __str.data(), __pos, __str.size());
}
@@ -3448,7 +3450,7 @@ basic_string<_CharT, _Traits, _Allocator
size_type __pos) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
- return _VSTD::__find<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
@@ -3457,7 +3459,7 @@ typename basic_string<_CharT, _Traits, _
basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
size_type __pos) const _NOEXCEPT
{
- return _VSTD::__find<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find<value_type, size_type, traits_type, npos>
(data(), size(), __c, __pos);
}
@@ -3470,7 +3472,7 @@ basic_string<_CharT, _Traits, _Allocator
size_type __n) const _NOEXCEPT
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
- return _VSTD::__rfind<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
@@ -3480,7 +3482,7 @@ typename basic_string<_CharT, _Traits, _
basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
size_type __pos) const _NOEXCEPT
{
- return _VSTD::__rfind<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
(data(), size(), __str.data(), __pos, __str.size());
}
@@ -3491,7 +3493,7 @@ basic_string<_CharT, _Traits, _Allocator
size_type __pos) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
- return _VSTD::__rfind<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
@@ -3500,7 +3502,7 @@ typename basic_string<_CharT, _Traits, _
basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
size_type __pos) const _NOEXCEPT
{
- return _VSTD::__rfind<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
(data(), size(), __c, __pos);
}
@@ -3513,7 +3515,7 @@ basic_string<_CharT, _Traits, _Allocator
size_type __n) const _NOEXCEPT
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
- return _VSTD::__find_first_of<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
@@ -3523,7 +3525,7 @@ typename basic_string<_CharT, _Traits, _
basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
size_type __pos) const _NOEXCEPT
{
- return _VSTD::__find_first_of<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
(data(), size(), __str.data(), __pos, __str.size());
}
@@ -3534,7 +3536,7 @@ basic_string<_CharT, _Traits, _Allocator
size_type __pos) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
- return _VSTD::__find_first_of<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
@@ -3556,7 +3558,7 @@ basic_string<_CharT, _Traits, _Allocator
size_type __n) const _NOEXCEPT
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
- return _VSTD::__find_last_of<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
@@ -3566,7 +3568,7 @@ typename basic_string<_CharT, _Traits, _
basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
size_type __pos) const _NOEXCEPT
{
- return _VSTD::__find_last_of<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
(data(), size(), __str.data(), __pos, __str.size());
}
@@ -3577,7 +3579,7 @@ basic_string<_CharT, _Traits, _Allocator
size_type __pos) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
- return _VSTD::__find_last_of<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
@@ -3599,7 +3601,7 @@ basic_string<_CharT, _Traits, _Allocator
size_type __n) const _NOEXCEPT
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
- return _VSTD::__find_first_not_of<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
@@ -3609,7 +3611,7 @@ typename basic_string<_CharT, _Traits, _
basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
size_type __pos) const _NOEXCEPT
{
- return _VSTD::__find_first_not_of<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __str.data(), __pos, __str.size());
}
@@ -3620,7 +3622,7 @@ basic_string<_CharT, _Traits, _Allocator
size_type __pos) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
- return _VSTD::__find_first_not_of<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
@@ -3630,7 +3632,7 @@ typename basic_string<_CharT, _Traits, _
basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
size_type __pos) const _NOEXCEPT
{
- return _VSTD::__find_first_not_of<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __c, __pos);
}
@@ -3643,7 +3645,7 @@ basic_string<_CharT, _Traits, _Allocator
size_type __n) const _NOEXCEPT
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
- return _VSTD::__find_last_not_of<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
@@ -3653,7 +3655,7 @@ typename basic_string<_CharT, _Traits, _
basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
size_type __pos) const _NOEXCEPT
{
- return _VSTD::__find_last_not_of<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __str.data(), __pos, __str.size());
}
@@ -3664,7 +3666,7 @@ basic_string<_CharT, _Traits, _Allocator
size_type __pos) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
- return _VSTD::__find_last_not_of<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
@@ -3674,7 +3676,7 @@ typename basic_string<_CharT, _Traits, _
basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
size_type __pos) const _NOEXCEPT
{
- return _VSTD::__find_last_not_of<value_type, size_type, traits_type, npos>
+ return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __c, __pos);
}
More information about the cfe-commits
mailing list