]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/include/bits/stl_algo.h
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / stl_algo.h
index c60780545140a9a62b4faec0a65aeb9429169c72..3d37091a9b4bc4c719316a903750fca43e93eaf9 100644 (file)
@@ -1,6 +1,6 @@
 // Algorithm implementation -*- C++ -*-
 
-// Copyright (C) 2001-2022 Free Software Foundation, Inc.
+// Copyright (C) 2001-2023 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
 #define _STL_ALGO_H 1
 
 #include <bits/algorithmfwd.h>
+#include <bits/stl_algobase.h>
 #include <bits/stl_heap.h>
-#include <bits/stl_tempbuf.h>  // for _Temporary_buffer
 #include <bits/predefined_ops.h>
 
 #if __cplusplus >= 201103L
 #include <bits/uniform_int_dist.h>
 #endif
 
-#if _GLIBCXX_HOSTED && (__cplusplus <= 201103L || _GLIBCXX_USE_DEPRECATED)
-#include <cstdlib>          // for rand
+#if _GLIBCXX_HOSTED
+# include <bits/stl_tempbuf.h>  // for _Temporary_buffer
+# if (__cplusplus <= 201103L || _GLIBCXX_USE_DEPRECATED)
+#  include <cstdlib>        // for rand
+# endif
 #endif
 
 // See concept_check.h for the __glibcxx_*_requires macros.
@@ -1491,6 +1494,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
        }
     }
 
+#if _GLIBCXX_HOSTED
   // partition
 
   /// This is a helper function...
@@ -1616,6 +1620,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
       return std::__stable_partition(__first, __last,
                                     __gnu_cxx::__ops::__pred_iter(__pred));
     }
+#endif // HOSTED
 
   /// @cond undocumented
 
@@ -2453,13 +2458,14 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
 
          _BidirectionalIterator __new_middle
            = std::__rotate_adaptive(__first_cut, __middle, __second_cut,
-                                    __len1 - __len11, __len22,
+                                    _Distance(__len1 - __len11), __len22,
                                     __buffer, __buffer_size);
          std::__merge_adaptive_resize(__first, __first_cut, __new_middle,
                                       __len11, __len22,
                                       __buffer, __buffer_size, __comp);
          std::__merge_adaptive_resize(__new_middle, __second_cut, __last,
-                                      __len1 - __len11, __len2 - __len22,
+                                      _Distance(__len1 - __len11),
+                                      _Distance(__len2 - __len22),
                                       __buffer, __buffer_size, __comp);
        }
     }
@@ -2526,7 +2532,6 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
          _ValueType;
       typedef typename iterator_traits<_BidirectionalIterator>::difference_type
          _DistanceType;
-      typedef _Temporary_buffer<_BidirectionalIterator, _ValueType> _TmpBuf;
 
       if (__first == __middle || __middle == __last)
        return;
@@ -2534,6 +2539,8 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
       const _DistanceType __len1 = std::distance(__first, __middle);
       const _DistanceType __len2 = std::distance(__middle, __last);
 
+#if _GLIBCXX_HOSTED
+      typedef _Temporary_buffer<_BidirectionalIterator, _ValueType> _TmpBuf;
       // __merge_adaptive will use a buffer for the smaller of
       // [first,middle) and [middle,last).
       _TmpBuf __buf(__first, std::min(__len1, __len2));
@@ -2548,6 +2555,10 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
        std::__merge_adaptive_resize
          (__first, __middle, __last, __len1, __len2, __buf.begin(),
           _DistanceType(__buf.size()), __comp);
+#else
+      std::__merge_without_buffer
+       (__first, __middle, __last, __len1, __len2, __comp);
+#endif
     }
 
   /**
@@ -4584,7 +4595,6 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
              std::iter_swap(__i, __j);
          }
     }
-#endif
 
   /**
    *  @brief Shuffle the elements of a sequence using a random number
@@ -4628,6 +4638,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
            std::iter_swap(__i, __j);
        }
     }
+#endif // HOSTED
 #endif // C++11 || USE_DEPRECATED
 
   /**
@@ -5016,23 +5027,28 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
        _ValueType;
       typedef typename iterator_traits<_RandomAccessIterator>::difference_type
        _DistanceType;
-      typedef _Temporary_buffer<_RandomAccessIterator, _ValueType> _TmpBuf;
 
       if (__first == __last)
        return;
 
+#if _GLIBCXX_HOSTED
+      typedef _Temporary_buffer<_RandomAccessIterator, _ValueType> _TmpBuf;
       // __stable_sort_adaptive sorts the range in two halves,
       // so the buffer only needs to fit half the range at once.
       _TmpBuf __buf(__first, (__last - __first + 1) / 2);
 
       if (__builtin_expect(__buf.requested_size() == __buf.size(), true))
-       std::__stable_sort_adaptive(__first, __first + __buf.size(), __last,
-                                   __buf.begin(), __comp);
+       std::__stable_sort_adaptive(__first,
+                                   __first + _DistanceType(__buf.size()),
+                                   __last, __buf.begin(), __comp);
       else if (__builtin_expect(__buf.begin() == 0, false))
        std::__inplace_stable_sort(__first, __last, __comp);
       else
        std::__stable_sort_adaptive_resize(__first, __last, __buf.begin(),
                                           _DistanceType(__buf.size()), __comp);
+#else
+      std::__inplace_stable_sort(__first, __last, __comp);
+#endif
     }
 
   /**