Afadyfarag created this revision.
Afadyfarag added reviewers: clayborg, aprantl, JDevlieghere, EricWF.
Afadyfarag added a project: libc++.
Herald added a reviewer: mclow.lists.

1. Changes:

  libcxx/include/numeric


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70772

Files:
  libcxx/CMakeLists.txt
  libcxx/include/algorithm
  libcxx/include/forward_list
  libcxx/include/numeric

Index: libcxx/include/numeric
===================================================================
--- libcxx/include/numeric
+++ libcxx/include/numeric
@@ -143,7 +143,9 @@
 
 #include <__config>
 #include <iterator>
+#if _LIBCPP_STD_VER > 17 
 #include <limits> // for numeric_limits
+#endif
 #include <functional>
 #include <cmath> // for isnormal
 #include <version>
@@ -172,8 +174,13 @@
 _Tp
 accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op)
 {
-    for (; __first != __last; ++__first)
+    for (; __first != __last; ++__first) {
+#if _LIBCPP_STD_VER > 17
+        __init = __binary_op(_VSTD::move(__init), *__first);    
+#else
         __init = __binary_op(__init, *__first);
+#endif
+    }
     return __init;
 }
 
@@ -222,8 +229,13 @@
 inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2,
               _Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2)
 {
-    for (; __first1 != __last1; ++__first1, (void) ++__first2)
+    for (; __first1 != __last1; ++__first1, (void) ++__first2) {
+#if _LIBCPP_STD_VER > 17
+        __init = __binary_op1(_VSTD::move(__init), __binary_op2(*__first1, *__first2));
+#else
         __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
+#endif
+    }
     return __init;
 }
 
@@ -292,8 +304,13 @@
         *__result = __t;
         for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
         {
+#if _LIBCPP_STD_VER > 17
+            __t = __binary_op(_VSTD::move(__t), *__first);
+            *__result = __t;
+#else
             __t = __binary_op(__t, *__first);
             *__result = __t;
+#endif
         }
     }
     return __result;
@@ -442,7 +459,11 @@
         for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
         {
             typename iterator_traits<_InputIterator>::value_type __t2(*__first);
+#if _LIBCPP_STD_VER > 17
+            *__result = __binary_op(__t2, _VSTD::move(__t1));
+#else
             *__result = __binary_op(__t2, __t1);
+#endif
             __t1 = _VSTD::move(__t2);
         }
     }
Index: libcxx/include/forward_list
===================================================================
--- libcxx/include/forward_list
+++ libcxx/include/forward_list
@@ -1502,11 +1502,12 @@
 #endif  // _LIBCPP_CXX03_LANG
 
 template <class _Tp, class _Alloc>
-void
+decltype(auto)
 forward_list<_Tp, _Alloc>::remove(const value_type& __v)
 {
     forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
     iterator __e = end();
+    __VSTD::size_type __rm = 0;
     for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;)
     {
         if (__i.__get_begin()->__next_->__value_ == __v)
@@ -1515,6 +1516,7 @@
             for (; __j != __e && *__j == __v; ++__j)
                 ;
             __deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j);
+            ++__rm;
             if (__j == __e)
                 break;
             __i = __j;
@@ -1522,15 +1524,21 @@
         else
             ++__i;
     }
+#if _LIBCPP_STD_VER > 17
+    return __rm;
+#else
+    (void) __rm;
+#endif
 }
 
 template <class _Tp, class _Alloc>
 template <class _Predicate>
-void
+decltype(auto)
 forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred)
 {
     forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
     iterator __e = end();
+    __VSTD::size_type __rm = 0;
     for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;)
     {
         if (__pred(__i.__get_begin()->__next_->__value_))
@@ -1539,6 +1547,7 @@
             for (; __j != __e && __pred(*__j); ++__j)
                 ;
             __deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j);
+            ++__rm;
             if (__j == __e)
                 break;
             __i = __j;
@@ -1546,6 +1555,11 @@
         else
             ++__i;
     }
+#if _LIBCPP_STD_VER > 17
+    return __rm;
+#else
+    (void) __rm;
+#endif
 }
 
 template <class _Tp, class _Alloc>
Index: libcxx/include/algorithm
===================================================================
--- libcxx/include/algorithm
+++ libcxx/include/algorithm
@@ -281,6 +281,10 @@
 template <class ForwardIterator, class OutputIterator>
     OutputIterator
     rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result);
+ 
+template<class ForwardIterator>
+    constexpr ForwardIterator shift_left(ForwardIterator first, ForwardIterator last,
+    typename iterator_traits<ForwardIterator>::difference_type n);
 
 template <class RandomAccessIterator>
     void
@@ -3107,6 +3111,41 @@
 }
 #endif
 
+// shift_left
+#if _LIBCPP_STD_VER > 17
+template<class _ForwardIterator>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+_ForwardIterator shift_left(_ForwardIterator __first, _ForwardIterator __last,
+                                      difference_type_t<_ForwardIterator> __d)
+{
+    if (__d <= 0)
+        return __last;
+    
+    const auto __vf = *__first;
+    const auto __vl = *__last;
+    auto begin      = __vf;
+    
+    if constexpr (__is_random_access_iterator<_ForwardIterator>::value)
+    {
+        if (__d >= __vl - __vf)
+        {
+            return __first;
+        }
+        begin += __d;
+    }
+    else
+    {
+        for (; 0 < __d; --__d)
+        {
+            if (begin == __vl)
+                return __first;
+            ++begin;
+        }
+    }
+    return __first;
+}
+#endif
+
 template <class _PopulationIterator, class _SampleIterator, class _Distance,
           class _UniformRandomNumberGenerator>
 _LIBCPP_INLINE_VISIBILITY
Index: libcxx/CMakeLists.txt
===================================================================
--- libcxx/CMakeLists.txt
+++ libcxx/CMakeLists.txt
@@ -533,6 +533,16 @@
 # Thus, we do nothing and hope we don't accidentally include any of the C++
 # headers
 add_compile_flags_if_supported(-nostdinc++)
+add_compile_flags_if_supported(-fcolor-diagnostics)
+
+option (FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." FALSE)
+if (${FORCE_COLORED_OUTPUT})
+    if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
+       add_compile_options (-fdiagnostics-color=always)
+    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+       add_compile_options (-fcolor-diagnostics)
+    endif ()
+endif ()
 
 # Hide all inline function definitions which have not explicitly been marked
 # visible. This prevents new definitions for inline functions from appearing in
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] [PATCH] D707... Fady Farag via Phabricator via lldb-commits

Reply via email to