// 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.
}
}
+#if _GLIBCXX_HOSTED
// partition
/// This is a helper function...
return std::__stable_partition(__first, __last,
__gnu_cxx::__ops::__pred_iter(__pred));
}
+#endif // HOSTED
/// @cond undocumented
_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);
}
}
_ValueType;
typedef typename iterator_traits<_BidirectionalIterator>::difference_type
_DistanceType;
- typedef _Temporary_buffer<_BidirectionalIterator, _ValueType> _TmpBuf;
if (__first == __middle || __middle == __last)
return;
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));
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
}
/**
std::iter_swap(__i, __j);
}
}
-#endif
/**
* @brief Shuffle the elements of a sequence using a random number
std::iter_swap(__i, __j);
}
}
+#endif // HOSTED
#endif // C++11 || USE_DEPRECATED
/**
_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
}
/**