Path: blob/main/system/lib/libcxx/src/algorithm.cpp
6175 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include <algorithm>9#include <bit>1011_LIBCPP_BEGIN_NAMESPACE_STD1213template <class Comp, class RandomAccessIterator>14void __sort(RandomAccessIterator first, RandomAccessIterator last, Comp comp) {15if (first == last) // log(0) is undefined, so don't try computing the depth16return;1718auto depth_limit = 2 * std::__bit_log2(static_cast<size_t>(last - first));1920// Only use bitset partitioning for arithmetic types. We should also check21// that the default comparator is in use so that we are sure that there are no22// branches in the comparator.23std::__introsort<_ClassicAlgPolicy,24ranges::less,25RandomAccessIterator,26__use_branchless_sort<ranges::less, RandomAccessIterator>>(first, last, ranges::less{}, depth_limit);27}2829// clang-format off30template void __sort<__less<char>&, char*>(char*, char*, __less<char>&);31#if _LIBCPP_HAS_WIDE_CHARACTERS32template void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);33#endif34template void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);35template void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);36template void __sort<__less<short>&, short*>(short*, short*, __less<short>&);37template void __sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);38template void __sort<__less<int>&, int*>(int*, int*, __less<int>&);39template void __sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);40template void __sort<__less<long>&, long*>(long*, long*, __less<long>&);41template void __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);42template void __sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);43template void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&);44template void __sort<__less<float>&, float*>(float*, float*, __less<float>&);45template void __sort<__less<double>&, double*>(double*, double*, __less<double>&);46template void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);47// clang-format on4849_LIBCPP_END_NAMESPACE_STD505152