diff options
author | mikhnenko <[email protected]> | 2025-02-25 10:55:30 +0300 |
---|---|---|
committer | mikhnenko <[email protected]> | 2025-02-25 11:10:50 +0300 |
commit | ba3f1646a3a22daceac94dd0cd330152b1d5b5b5 (patch) | |
tree | 16da0d516f0c768c219e6f0fc7351676e390873f /contrib/libs/cxxsupp/libcxx/include/__numeric | |
parent | dda9be9e1fde150b4473d9d10ec1a0d3829f7482 (diff) |
Update libcxx to 8 July 2024
{% cut "Change log" %}
```
[libc++] Add a test case for std::bit_cast with std::complex (#97751)
[libc++] Update status after the St. Louis meeting. (#97951)
[libc++] Guard transitive include of `<locale>` with availability macro (#97869)
[libc++] Restore `__synth_three_way` lambda (#90398)
[libc++][TZDB] Makes implementation experimental. (#95657)
[libc++] Remove dead code from the locale base API and support code (#89070)
[libc++] Assume newer LLVM versions for not-yet-released macOS versions
[libc++] Remove annotations for GCC 13 and update the documentation (#97744)
[libc++][test] Updates sized deallocation tests. (#97833)
[libc++] Adds a missing include.
[libc++] Use __is_array if the builtin is fixed (#93037)
[libc++] Use _Complex for multiplication and division of complex floating point types (#83575)
[libc++] Adds a new feature-test macro generator class. (#90889)
[libc++][chrono] Fixes leap seconds. (#90070)
[libc++] Upgrade to GCC 14 (#97205)
[libc++] Fix the signatures of `std::rethrow_if_nested` (#91365)
[libc++] Use GCC compilers from compiler explorer (#97219)
Add a regression test for recent regression in pair. (#97355)
[libcxx][Docs] Correct link syntax in hardening docs
[libc++] Don't use a ppa for GCC
[libc++] Upgrade to GCC 14 in the CI (#95212)
[libc++abi] Fix test failures with GCC 14 (#95759)
[libc++] Clean up and update deployment target features (#96312)
[libc++] Fix how we pass /MANIFEST flag on Windows without clang-cl (#96967)
[libc++] Classify iota_view precondition (#96662)
[libc++] restrict the expected conversion constructor not compete against copy constructor (#96101)
"[libc++] Try again LWG3233 Broken requirements for shared_ptr converting constructors" (#96103)
[libc++] LWG3382: NTTP for `pair` and `array` (#85811)
[libc++] Get the GCC build mostly clean of warnings (#96604)
[libc++] P3029R1: Better `mdspan`'s CTAD - `std::extents` (#89015)
[libc++] Move allocator assertion into allocator_traits (#94750)
[libc++] change the visibility of libc++ header to public in libcxx module (#91240)
[libc++] Use _If for conditional_t (#96193)
[libc++] Remove the allocator<const T> extension (#96319)
[libc++] Fix incorrect overflow checking in std::lcm (#96310)
[libc++] Use __is_nothrow_destructible (#95766)
[libc++] Remove Windows-specific configuration from libcxx/test/CMakeLists.txt (#96330)
[libc++] Build with -fsized-deallocation (#96217)
[libc++] <experimental/simd> Add swap functions of simd reference (#86478)
[libc++] Fix deployment target Lit features (#94791)
[libc++] Workaround clang bug in __has_unique_object_representations (#95314)
[libc++] Remove <ostream> include from <chrono> (#96035)
[libc++] Fix triviality of std::pair for trivially copyable types without an assignment operator (#95444)
[libc++] Install Python packaging to resolve LLDB data formatter issues (#95971)
[libc++] Properly define _LIBCPP_HAS_NO_UNICODE in __config_site (#95138)
[libc++] Refactor<__type_traits/is_swappable.h> (#86822)
[libc++] Enable modernize-use-equals-delete (#93293)
[libc++] Test suite adjustments on macOS (#95835)
[libc++] Guard transitive include of `<locale>` with availability macro (#95686)
[libc++] Mark more types as trivially relocatable (#89724)
[libcxx] [ci] Simplify the mingw x86_64 configs (#95609)
[libc++][TZDB] Disables a failing test. (#95659)
[libc++] Add default copy ctor to "__chrono/exception.h" (#95338)
[libcxx][test][AIX] address more platform differences in locale tests (#94826)
[libc++] Remove unnecessary #ifdef guards around PSTL implementation details (#95268)
[libc++] Mark local_time test as a long test (#95170)
Update actions-runner version for libc++ builder images
[libc++] Move the implementation of CPU-based basis operations to namespace __pstl (#95267)
[libc++][modules] Mark as implemented. (#90091)
[libc++] Adds __cpp_lib_three_way_comparison FTM. (#91515)
[libc++] Overhaul the PSTL dispatching mechanism (#88131)
[libcxx] Correct and clean-up filesystem operations error_code paths (#88341)
[libc++][z/OS] Disable portion of formatter.char.funsigned-char.pass.cpp for no unicode (#94044)
[libc++] Mark a few functions in the dylib as noexcept (#94098)
[libc++] Fix UB in filesystem::__copy for non-existent destination. (#87615)
[libc++] Simplify the definition of string::operator== (#95000)
[libc++] Update with LWG issue number for shared-ptr constructor
[libc++] Tweak how we check constraints on shared_ptr(nullptr_t) (#94996)
[HWASan] make get_info.local_time.pass.cpp UNSUPPORTED
[libc++] Fix endianness for algorithm mismatch (#93082)
[HWASan] skip libcxx test that times out with hwasan
[libc++][TZDB] Implements zoned_traits. (#91059)
[libc++][test] Avoid `-Wunused-variable` warnings in mutex tests (#94907)
[libc++] Fix invalid escape sequences in Python comments (#94032)
[libc++][TZDB] Implements time_zone::to_local. (#91003)
[libc++][TZDB] Implements time_zone::to_sys. (#90901)
[libc++][TZDB] Implements time_zone::to_sys. (#90394)
[libc++][TZDB] Implements time_zone get_info(local_time). (#89537)
[libc++] Undeprecate shared_ptr atomic access APIs (#92920)
[libc++][regex] Correctly adjust match prefix for zero-length matches. (#94550)
[libc++][test][AIX] Only XFAIL atomic tests for before clang 19 (#94646)
[libc++] Fix naming of value template parameters (#76888)
[libc++][hardening] Finish documenting hardening. (#92021)
Fix detection of __datasizeof with Clang. (#94174)
[libc++] Fix SyntaxWarning messages from python 3.12 (#93637)
[libc++] [test] Consistently use `REQUIRES: has-unix-headers` (#94122)
[libc++] Add missing noexcept to span constructor (#94381)
Remove act from builder image. It never turned out to be useful
[libc++] Adjust XFAIL for quick_exit (#94274)
[libc++] Properly detect whether C++20 modules are supported by the compiler (#94275)
[libc++] Handle 0 size case for testing support operator new (#93834)
[libc++] Fix regression about parsing leading decimal points (#93989)
[libc++][test] Mark `optional` test functions as `TEST_CONSTEXPR_CXX20` (#94172)
[clang][Modules] Remove unnecessary includes of `Module.h` (#93417)
[libc++] Don't give functions C linkage (#94102)
[libc++] [test] Cleanup compile-only tests (#94121)
[libc++] [test] Fix `__has_include` usage, expand condvarany and spaceship coverage (#94120)
[libc++] Fix `std::atomic::wait` ulock wait UL_COMPARE_AND_WAIT64 (#92783)
Fix order of include flags for the target & regular include paths. (#93547)
[libc++] Fix failures with GCC 14 (#92663)
[libc++] Remove the inline namespace for std::filesystem in ABIv2 (#92971)
[runtimes] Correctly apply libdir subdir for multilib (#93354)
[clang] Preserve Qualifiers and type sugar in TemplateNames (#93433)
[libc++][test] Close LWG3018 and add tests (#93047)
[runtimes][CMake] Simplify the propagation of test dependencies (#93558)
[runtimes] Reintroduce a way to select the compiler used for the test suite (#93542)
[libc++] Make the __availability header a sub-header of __config (#93083)
[libc++][test] Close LWG3238 and add tests (#93043)
[libc++] LWG3223 Broken requirements for shared_ptr converting constructors (#93071)
[libc++][test] Close LWG3382 and add tests (#93039)
[libc++] [test] Fix portability issues for MSVC (#93259)
[libc++] [test] Fix MSVC warnings (#93257)
[libc++] Mark P2845R8 `__cpp_lib_format_path` and P2587R3 `__cpp_lib_to_string` as C++26 (#93255)
[libc++] Split up ABI and platform configuration to their own headers (#90863)
[libc++][pstl] Merge all frontend functions for the PSTL (#89219)
[libcxx][test][AIX] Fix the thousands_sep expectation for fr_FR locales (#92312)
[libcxx] [test] Use `shlex.quote()` to fix Python 3.13 compatibility (#93376)
[libc++] Remove libcxx/include/libcxx.imp
Revise IDE folder structure (#89755)
[libc++][test] Close LWG3045 (#93053)
[libc++] Remove a few unused includes of trivially_copyable.h (#93200)
[test][libcxx] Update deallocation after #90373 (#93145)
[libc++] Refactor tests for std::condition_variable (#91530)
Removed redundant template in '__delete_node()' member function of '__forward_list_base' and '__list_imp' classes. (#84323)
[libc++][pstl] Improve exception handling (#88998)
[WebAssembly] Upstream misc. EH changes (#92990)
[libc++] <experimental/simd> Add copy functions for class simd/simd_mask (#78935)
[libc++][vector] Inline remaining constructors filling vector with the same value (#82068)
Reland "[clang] Enable sized deallocation by default in C++14 onwards" (#90373)
[libc++] Implement C++20 atomic_ref (#76647)
[libc++] Refactor flaky tests for std::shared_lock (#91779)
[libcxx] [test] Detect mingw-w64 headers compatible with C++ module builds (#92893)
[libc++] LWG2381: Inconsistency in parsing floating point numbers (#77948)
[libcxx] removes unnecessary traits from `has_unique_object_representations` (#69241)
[libc++][z/OS] Switch to use TEST_HAS_NO_INT128 as per comment in PR 92261 (#92434)
[libcxx] Add cast to avoid pointer casting warning on Windows (#92738)
[libcxx] locale.cpp: Move build_name helper into unnamed namespace (#92461)
[libcxx][libcxxabi] Fix build for OpenBSD (#92186)
[libc++] LWG3672: `common_iterator::operator->()` should return by value (#87899)
[libc++][z/OS] Correct a definition of __native_vector_size (#91995)
[libc++][z/OS] Fixup two linear_congruential_engine tests (#92261)
[libc++][test] `__cpp_lib_within_lifetime` -> `__cpp_lib_is_within_lifetime` (#91896)
Fix typo "indicies" (#92232)
[libcxx][test] Fix numpunct grouping tests on AIX (#91781)
[libcxx] [test] Fix the locale ctype widen tests on AIX (#91744)
[libc++] Vectorize std::mismatch with trivially equality comparable types (#87716)
[libc++] Make `constexpr std::variant`. Implement P2231R1 (#83335)
[libc++][doc] Updates Spaceship status page.
[libc++][ASan] Fix std::basic_string trait type (#91590)
[libc++][test] Fixes constexpr char_traits. (#90981)
[libc++][functional] P2944R3 (partial): Comparisons for `reference_wrapper` (`reference_wrapper` operators only) (#88384)
[libc++][CI] Reenables clang-tidy. (#90077)
[libc++] Implement std::gcd using the binary version (#77747)
[ASan][libc++] Turn on ASan annotations for short strings (#79536)
[AIX][libc++] Enable clang_modules_include.gen.py tests (#90971)
[libc++] Rename _LIBCPP_INTRODUCED_foo_MARKUP to _LIBCPP_INTRODUCED_foo_ATTRIBUTE (#91269)
[libc++] Fix P1206R7 feature test macros (#90914)
[libc++] Adjust some of the [rand.dist] critical values that are too strict (#88669)
[libc++][modules] Uses _LIBCPP_USING_IF_EXISTS. (#90409)
Bump actions runner image used for libc++'s builders.
[libcxx] Align `__recommend() + 1` by __endian_factor (#90292)
[libc++] Granularize <ostream> (#85537)
[libc++] Remove a few __has_foo defines in __config (#90511)
[libc++] Remove _LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS (#90512)
[libcxx][ci] In picolib build, ask clang for the normalised triple (#90722)
[libc++][ranges] Implement LWG4053 and LWG4054 (#88612)
[libc++] Some tests are missing include for `numeric_limits` (#90345)
[libc++] Mark scoped_lock and unique_lock constructors as [[nodiscard]] (#89397)
[libc++] Improve libc++ tests when using optimizations (#88897)
[libc++][modules] Enable installation by default. (#90094)
[libc++][format] Improves escaping performance. (#88533)
[libcxx] Remove empty ~__no_destroy (#89882)
[libc++][ranges] Exports operator|. (#90071)
[C++17] Support __GCC_[CON|DE]STRUCTIVE_SIZE (#89446)
[libc++][ranges] LWG3984: ranges::to's recursion branch may be ill-formed (#87964)
[clang] Enable sized deallocation by default in C++14 onwards (#83774)
[libc++][format] Improves escaping. (#88283)
[libc++] Implement LWG4023 (#87513)
[libc++] Reformulate availability in terms of LLVM releases (#87563)
[libc++] Reorganize the std::variant macros (#89419)
[libc++][format] Adds an escaped output benchmark. (#88020)
[libc++] Makes saturation functions privately available. (#89503)
[libcxx] [modules] Add _LIBCPP_USING_IF_EXISTS on aligned_alloc (#89827)
[libc++][TZDB] Fixes reverse time lookups. (#89502)
[libc++][doc] Updates module build instructions. (#89413)
[libc++][chrono] Fixes format output of negative values. (#89408)
[libc++][ranges] export `std::ranges::range_adaptor_closure` (#89793)
[libc++][ranges] P2387R3: Pipe support for user-defined range adaptors (#89148)
[libc++] Add some private headers to libcxx.imp (#89568)
[libc++] Remove _LIBCPP_DISABLE_NODISCARD_EXTENSIONS and refactor the tests (#87094)
[libc++] Remove stray CMake install step for modulemap file (#89394)
[libc++] Don't commit libcxx.imp (#89391)
[libc++] Removes a Clang 16 Windows workaround. (#88560)
[libc++][TZDB] Renames incomplete. (#89250)
[libc++] Optimize char_traits a bit (#72799)
[libc++] Fix usage of 'exclude_from_explicit_instantiation' attribute on local class members (#89377)
linear_congruential_engine: add using more precision to prevent overflow (#81583)
CompilerRT: Normalize COMPILER_RT_DEFAULT_TARGET_TRIPLE (#89234)
[libc++][TZDB] Adds local_info formatter. (#86256)
[libc++][pstl] Move the CPU algorithm implementations to __pstl (#89109)
[libc++][TZDB] Adds sys_info formatter. (#85896)
[libc++][pstl] Promote CPU backends to top-level backends (#88968)
[libc++][chrono] Improves date formatting. (#86127)
[libc++] Add missing iterator requirement checks in the PSTL (#88127)
[libc++][TZDB] Improves time zone format specifiers. (#85797)
[libc++][chrono] Disables a test.
[libc++][doc] Documents -DLIBCXX_INSTALL_MODULES=ON. (#88547)
[libc++][test] Removes Clang 16 validation. (#88558)
[libc++] Removes deprecated _LIBCPP_ENABLE_<VERSION>_REMOVED_FEATURES macros (#88548)
[libc++][modules] Removes some validation quirks. (#88031)
[libc++] Deprecate the C++20 synchronization library before C++20 (#86410)
[libc++] Use availability to rely on key functions for bad_expected_access and bad_function_call (#87390)
[libc++] Rename __cpu_traits functions (#88741)
[libc++][CI] Tests LLDB libc++ data formatters. (#88312)
[libc++] Add a utility to check whether a range is valid (#87665)
[libc++][PSTL] Introduce cpu traits (#88134)
[libc++][RFC] Only include what is required by-version in the umbrella headers (#83740)
[libc++] Deprecated `shared_ptr` Atomic Access APIs as per P0718R2 & Implemented P2869R3: Remove Deprecated `shared_ptr` Atomic Access APIs from C++26 (#87111)
[libc++][TZDB] Removes test_indian_kerguelen test.
[libc++][TZDZ] Validates the database version.
[libc++] Undeprecate POSIX STREAM macros. (#88296)
[libc++] Marks a variable const. (#88562)
[libc++][CMake] Removes LIBCXX_ENABLE_CLANG_TIDY. (#85794)
[tzdb] Replace shared_mutex with mutex. (#87929)
[libc++] P3029R1: Better `mdspan`'s CTAD (#87873)
[libc++][ranges] LWG3736: move_iterator missing disable_sized_sentinel_for specialization (#85611)
[libc++] LWG3643: Missing `constexpr` in `std::counted_iterator` (#87901)
[libcxx] applies changes regarding post-commit feedback to #75259 (#76534)
[libc++] Fix -Wgnu-include-next in stddef.h (#88214)
[libcxx] Use generic builtins for popcount, clz and ctz (#86563)
[libc++] Adds a global private constructor tag. (#87920)
[libc++] Removes Clang-16 support. (#87810)
[lib++][CI] Changes bootstrap build type. (#88175)
[libc++][CI] Updates Docker LLDB dependencies. (#88174)
[libc++][chrono] Adds the sys_info class. (#85619)
[libc++][format] Switches to Unicode 15.1. (#86543)
[libc++] Avoids using ENODATA. (#86165)
[libc++][TZDB] Fixes relative path resolving. (#87882)
[libc++][format] adds a basic fuzzer test. (#87883)
[libc++] Add test coverage for our implementation of LWG4031 (#87508)
[libc++] Implement `bind_back` (#81055)
[libc++][format] Fixed `println.blank_line.sh.cpp` test on llvm-clang-win-x-* configurations (#88011)
[libc++][doc] Updates format status page.
[libc++][format] P3142R0: Printing Blank Lines with `println` (#87277)
[libc++] Optimize ranges::minmax (#87335)
[libc++] Implement LWG3430 disallow implicit conversion of the source arguments to `std::filesystem::path` when constructing `std::basic_*fstream` (#85079)
[libc++] P2872R3: Remove ``wstring_convert`` From C++26 (#87100)
Fix issue with never-constexpr __construct_at in C++ < 20. (#87403)
[libcxx] coerce formatter precision to int (#87738)
[libc++][CI] Updates to Clang 19. (#85301)
[libc++][chrono] Completes the tzdb class. (#82157)
[libc++][oss-fuzz] Updates C++ version used. (#87531)
[libc++] P2867R1: Remove Deprecated `strstream`s From C++26 (#87107)
[libc++] Fix copy/pasta error in atomic tests for `atomic_compare_exchange_{weak,strong}` (#87135)
[libc++] Mark some recent LWG issues and papers as done (#87502)
[libc++][chrono] Loads leap-seconds.list in tzdb. (#82113)
[libc++] Disables -Wweak-vtables diagnostics. (#85577)
[libc++] Update status page after the Tokyo meeting (#87395)
[libc++] Upstream ptrauth support in libc++ and libc++abi (#84573)
[libc++] Fix tests on musl (#85085) (#86934)
[libc++] Add a static_assert for a Mandates in seed_seq (#86992)
[libc++][ranges] Avoid using `distance` in `ranges::contains_subrange` (#87155)
[libc++] `std::ranges::advance`: avoid unneeded bounds checks when advancing iterator (#84126)
```
{% endcut %}
commit_hash:45feb9db5b173f12bf29de2a3ee73006d4371a4e
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/include/__numeric')
5 files changed, 267 insertions, 287 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/include/__numeric/gcd_lcm.h b/contrib/libs/cxxsupp/libcxx/include/__numeric/gcd_lcm.h index 48df2338051..9be6cf8516b 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__numeric/gcd_lcm.h +++ b/contrib/libs/cxxsupp/libcxx/include/__numeric/gcd_lcm.h @@ -10,7 +10,9 @@ #ifndef _LIBCPP___NUMERIC_GCD_LCM_H #define _LIBCPP___NUMERIC_GCD_LCM_H +#include <__algorithm/min.h> #include <__assert> +#include <__bit/countr.h> #include <__config> #include <__type_traits/common_type.h> #include <__type_traits/is_integral.h> @@ -35,7 +37,7 @@ struct __ct_abs; template <typename _Result, typename _Source> struct __ct_abs<_Result, _Source, true> { - _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI _Result operator()(_Source __t) const noexcept { + constexpr _LIBCPP_HIDE_FROM_ABI _Result operator()(_Source __t) const noexcept { if (__t >= 0) return __t; if (__t == numeric_limits<_Source>::min()) @@ -46,20 +48,58 @@ struct __ct_abs<_Result, _Source, true> { template <typename _Result, typename _Source> struct __ct_abs<_Result, _Source, false> { - _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI _Result operator()(_Source __t) const noexcept { return __t; } + constexpr _LIBCPP_HIDE_FROM_ABI _Result operator()(_Source __t) const noexcept { return __t; } }; template <class _Tp> -_LIBCPP_CONSTEXPR _LIBCPP_HIDDEN _Tp __gcd(_Tp __m, _Tp __n) { - static_assert((!is_signed<_Tp>::value), ""); - return __n == 0 ? __m : std::__gcd<_Tp>(__n, __m % __n); +constexpr _LIBCPP_HIDDEN _Tp __gcd(_Tp __a, _Tp __b) { + static_assert(!is_signed<_Tp>::value, ""); + + // From: https://lemire.me/blog/2013/12/26/fastest-way-to-compute-the-greatest-common-divisor + // + // If power of two divides both numbers, we can push it out. + // - gcd( 2^x * a, 2^x * b) = 2^x * gcd(a, b) + // + // If and only if exactly one number is even, we can divide that number by that power. + // - if a, b are odd, then gcd(2^x * a, b) = gcd(a, b) + // + // And standard gcd algorithm where instead of modulo, minus is used. + + if (__a < __b) { + _Tp __tmp = __b; + __b = __a; + __a = __tmp; + } + if (__b == 0) + return __a; + __a %= __b; // Make both argument of the same size, and early result in the easy case. + if (__a == 0) + return __b; + + int __az = std::__countr_zero(__a); + int __bz = std::__countr_zero(__b); + int __shift = std::min(__az, __bz); + __a >>= __az; + __b >>= __bz; + do { + _Tp __diff = __a - __b; + if (__a > __b) { + __a = __b; + __b = __diff; + } else { + __b = __b - __a; + } + if (__diff != 0) + __b >>= std::__countr_zero(__diff); + } while (__b != 0); + return __a << __shift; } template <class _Tp, class _Up> -_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI common_type_t<_Tp, _Up> gcd(_Tp __m, _Up __n) { - static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to gcd must be integer types"); - static_assert((!is_same<__remove_cv_t<_Tp>, bool>::value), "First argument to gcd cannot be bool"); - static_assert((!is_same<__remove_cv_t<_Up>, bool>::value), "Second argument to gcd cannot be bool"); +constexpr _LIBCPP_HIDE_FROM_ABI common_type_t<_Tp, _Up> gcd(_Tp __m, _Up __n) { + static_assert(is_integral<_Tp>::value && is_integral<_Up>::value, "Arguments to gcd must be integer types"); + static_assert(!is_same<__remove_cv_t<_Tp>, bool>::value, "First argument to gcd cannot be bool"); + static_assert(!is_same<__remove_cv_t<_Up>, bool>::value, "Second argument to gcd cannot be bool"); using _Rp = common_type_t<_Tp, _Up>; using _Wp = make_unsigned_t<_Rp>; return static_cast<_Rp>( @@ -67,21 +107,23 @@ _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI common_type_t<_Tp, _Up> gcd(_Tp __m, _Up } template <class _Tp, class _Up> -_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI common_type_t<_Tp, _Up> lcm(_Tp __m, _Up __n) { - static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to lcm must be integer types"); - static_assert((!is_same<__remove_cv_t<_Tp>, bool>::value), "First argument to lcm cannot be bool"); - static_assert((!is_same<__remove_cv_t<_Up>, bool>::value), "Second argument to lcm cannot be bool"); +constexpr _LIBCPP_HIDE_FROM_ABI common_type_t<_Tp, _Up> lcm(_Tp __m, _Up __n) { + static_assert(is_integral<_Tp>::value && is_integral<_Up>::value, "Arguments to lcm must be integer types"); + static_assert(!is_same<__remove_cv_t<_Tp>, bool>::value, "First argument to lcm cannot be bool"); + static_assert(!is_same<__remove_cv_t<_Up>, bool>::value, "Second argument to lcm cannot be bool"); if (__m == 0 || __n == 0) return 0; using _Rp = common_type_t<_Tp, _Up>; _Rp __val1 = __ct_abs<_Rp, _Tp>()(__m) / std::gcd(__m, __n); _Rp __val2 = __ct_abs<_Rp, _Up>()(__n); - _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN((numeric_limits<_Rp>::max() / __val1 > __val2), "Overflow in lcm"); - return __val1 * __val2; + _Rp __res; + [[maybe_unused]] bool __overflow = __builtin_mul_overflow(__val1, __val2, &__res); + _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(!__overflow, "Overflow in lcm"); + return __res; } -#endif // _LIBCPP_STD_VER +#endif // _LIBCPP_STD_VER >= 17 _LIBCPP_END_NAMESPACE_STD diff --git a/contrib/libs/cxxsupp/libcxx/include/__numeric/pstl.h b/contrib/libs/cxxsupp/libcxx/include/__numeric/pstl.h new file mode 100644 index 00000000000..7557686a366 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/include/__numeric/pstl.h @@ -0,0 +1,174 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___NUMERIC_PSTL_H +#define _LIBCPP___NUMERIC_PSTL_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 + +# include <__functional/identity.h> +# include <__functional/operations.h> +# include <__iterator/cpp17_iterator_concepts.h> +# include <__iterator/iterator_traits.h> +# include <__pstl/backend.h> +# include <__pstl/dispatch.h> +# include <__pstl/handle_exception.h> +# include <__type_traits/enable_if.h> +# include <__type_traits/is_execution_policy.h> +# include <__type_traits/remove_cvref.h> +# include <__utility/forward.h> +# include <__utility/move.h> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _ExecutionPolicy, + class _ForwardIterator, + class _Tp, + class _BinaryOperation, + class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, + enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> +_LIBCPP_HIDE_FROM_ABI _Tp reduce( + _ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Tp __init, _BinaryOperation __op) { + _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "reduce requires ForwardIterators"); + using _Implementation = __pstl::__dispatch<__pstl::__reduce, __pstl::__current_configuration, _RawPolicy>; + return __pstl::__handle_exception<_Implementation>( + std::forward<_ExecutionPolicy>(__policy), + std::move(__first), + std::move(__last), + std::move(__init), + std::move(__op)); +} + +template <class _ExecutionPolicy, + class _ForwardIterator, + class _Tp, + class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, + enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> +_LIBCPP_HIDE_FROM_ABI _Tp +reduce(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Tp __init) { + _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "reduce requires ForwardIterators"); + using _Implementation = __pstl::__dispatch<__pstl::__reduce, __pstl::__current_configuration, _RawPolicy>; + return __pstl::__handle_exception<_Implementation>( + std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), std::move(__init), plus{}); +} + +template <class _ExecutionPolicy, + class _ForwardIterator, + class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, + enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> +_LIBCPP_HIDE_FROM_ABI __iter_value_type<_ForwardIterator> +reduce(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last) { + _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "reduce requires ForwardIterators"); + using _Implementation = __pstl::__dispatch<__pstl::__reduce, __pstl::__current_configuration, _RawPolicy>; + return __pstl::__handle_exception<_Implementation>( + std::forward<_ExecutionPolicy>(__policy), + std::move(__first), + std::move(__last), + __iter_value_type<_ForwardIterator>(), + plus{}); +} + +template <class _ExecutionPolicy, + class _ForwardIterator1, + class _ForwardIterator2, + class _Tp, + class _BinaryOperation1, + class _BinaryOperation2, + class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, + enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> +_LIBCPP_HIDE_FROM_ABI _Tp transform_reduce( + _ExecutionPolicy&& __policy, + _ForwardIterator1 __first1, + _ForwardIterator1 __last1, + _ForwardIterator2 __first2, + _Tp __init, + _BinaryOperation1 __reduce, + _BinaryOperation2 __transform) { + _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "transform_reduce requires ForwardIterators"); + _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "transform_reduce requires ForwardIterators"); + using _Implementation = + __pstl::__dispatch<__pstl::__transform_reduce_binary, __pstl::__current_configuration, _RawPolicy>; + return __pstl::__handle_exception<_Implementation>( + std::forward<_ExecutionPolicy>(__policy), + std::move(__first1), + std::move(__last1), + std::move(__first2), + std::move(__init), + std::move(__reduce), + std::move(__transform)); +} + +// This overload doesn't get a customization point because it's trivial to detect (through e.g. +// __desugars_to_v) when specializing the more general variant, which should always be preferred +template <class _ExecutionPolicy, + class _ForwardIterator1, + class _ForwardIterator2, + class _Tp, + class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, + enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> +_LIBCPP_HIDE_FROM_ABI _Tp transform_reduce( + _ExecutionPolicy&& __policy, + _ForwardIterator1 __first1, + _ForwardIterator1 __last1, + _ForwardIterator2 __first2, + _Tp __init) { + _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator1, "transform_reduce requires ForwardIterators"); + _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator2, "transform_reduce requires ForwardIterators"); + using _Implementation = + __pstl::__dispatch<__pstl::__transform_reduce_binary, __pstl::__current_configuration, _RawPolicy>; + return __pstl::__handle_exception<_Implementation>( + std::forward<_ExecutionPolicy>(__policy), + std::move(__first1), + std::move(__last1), + std::move(__first2), + std::move(__init), + plus{}, + multiplies{}); +} + +template <class _ExecutionPolicy, + class _ForwardIterator, + class _Tp, + class _BinaryOperation, + class _UnaryOperation, + class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, + enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> +_LIBCPP_HIDE_FROM_ABI _Tp transform_reduce( + _ExecutionPolicy&& __policy, + _ForwardIterator __first, + _ForwardIterator __last, + _Tp __init, + _BinaryOperation __reduce, + _UnaryOperation __transform) { + _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "transform_reduce requires ForwardIterators"); + using _Implementation = __pstl::__dispatch<__pstl::__transform_reduce, __pstl::__current_configuration, _RawPolicy>; + return __pstl::__handle_exception<_Implementation>( + std::forward<_ExecutionPolicy>(__policy), + std::move(__first), + std::move(__last), + std::move(__init), + std::move(__reduce), + std::move(__transform)); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___NUMERIC_PSTL_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__numeric/pstl_reduce.h b/contrib/libs/cxxsupp/libcxx/include/__numeric/pstl_reduce.h deleted file mode 100644 index f9f666c2bb3..00000000000 --- a/contrib/libs/cxxsupp/libcxx/include/__numeric/pstl_reduce.h +++ /dev/null @@ -1,109 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___NUMERIC_PSTL_REDUCE_H -#define _LIBCPP___NUMERIC_PSTL_REDUCE_H - -#include <__algorithm/pstl_frontend_dispatch.h> -#include <__config> -#include <__functional/identity.h> -#include <__iterator/iterator_traits.h> -#include <__numeric/pstl_transform_reduce.h> -#include <__type_traits/is_execution_policy.h> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 - -_LIBCPP_BEGIN_NAMESPACE_STD - -template <class> -void __pstl_reduce(); - -template <class _ExecutionPolicy, - class _ForwardIterator, - class _Tp, - class _BinaryOperation = plus<>, - class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, - enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<_Tp> -__reduce(_ExecutionPolicy&& __policy, - _ForwardIterator&& __first, - _ForwardIterator&& __last, - _Tp&& __init, - _BinaryOperation&& __op = {}) noexcept { - return std::__pstl_frontend_dispatch( - _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_reduce, _RawPolicy), - [&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _Tp __g_init, _BinaryOperation __g_op) { - return std::__transform_reduce( - __policy, std::move(__g_first), std::move(__g_last), std::move(__g_init), std::move(__g_op), __identity{}); - }, - std::move(__first), - std::move(__last), - std::move(__init), - std::move(__op)); -} - -template <class _ExecutionPolicy, - class _ForwardIterator, - class _Tp, - class _BinaryOperation = plus<>, - class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, - enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp -reduce(_ExecutionPolicy&& __policy, - _ForwardIterator __first, - _ForwardIterator __last, - _Tp __init, - _BinaryOperation __op = {}) { - auto __res = std::__reduce(__policy, std::move(__first), std::move(__last), std::move(__init), std::move(__op)); - if (!__res) - std::__throw_bad_alloc(); - return *std::move(__res); -} - -template <class _ExecutionPolicy, - class _ForwardIterator, - class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, - enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__iter_value_type<_ForwardIterator>> -__reduce(_ExecutionPolicy&& __policy, _ForwardIterator&& __first, _ForwardIterator&& __last) noexcept { - return std::__pstl_frontend_dispatch( - _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_reduce, _RawPolicy), - [&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last) { - return std::__reduce( - __policy, std::move(__g_first), std::move(__g_last), __iter_value_type<_ForwardIterator>()); - }, - std::move(__first), - std::move(__last)); -} - -template <class _ExecutionPolicy, - class _ForwardIterator, - class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, - enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> -_LIBCPP_HIDE_FROM_ABI __iter_value_type<_ForwardIterator> -reduce(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last) { - auto __res = std::__reduce(__policy, std::move(__first), std::move(__last)); - if (!__res) - std::__throw_bad_alloc(); - return *std::move(__res); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___NUMERIC_PSTL_REDUCE_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__numeric/pstl_transform_reduce.h b/contrib/libs/cxxsupp/libcxx/include/__numeric/pstl_transform_reduce.h deleted file mode 100644 index 2f412d41f7f..00000000000 --- a/contrib/libs/cxxsupp/libcxx/include/__numeric/pstl_transform_reduce.h +++ /dev/null @@ -1,156 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___NUMERIC_PSTL_TRANSFORM_REDUCE_H -#define _LIBCPP___NUMERIC_PSTL_TRANSFORM_REDUCE_H - -#include <__algorithm/pstl_backend.h> -#include <__algorithm/pstl_frontend_dispatch.h> -#include <__config> -#include <__functional/operations.h> -#include <__numeric/transform_reduce.h> -#include <__type_traits/is_execution_policy.h> -#include <__utility/move.h> -#include <optional> - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - -#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 - -_LIBCPP_BEGIN_NAMESPACE_STD - -template <class _ExecutionPolicy, - class _ForwardIterator1, - class _ForwardIterator2, - class _Tp, - class _BinaryOperation1, - class _BinaryOperation2, - class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, - enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> -_LIBCPP_HIDE_FROM_ABI optional<_Tp> __transform_reduce( - _ExecutionPolicy&&, - _ForwardIterator1&& __first1, - _ForwardIterator1&& __last1, - _ForwardIterator2&& __first2, - _Tp&& __init, - _BinaryOperation1&& __reduce, - _BinaryOperation2&& __transform) noexcept { - using _Backend = typename __select_backend<_RawPolicy>::type; - return std::__pstl_transform_reduce<_RawPolicy>( - _Backend{}, - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__init), - std::move(__reduce), - std::move(__transform)); -} - -template <class _ExecutionPolicy, - class _ForwardIterator1, - class _ForwardIterator2, - class _Tp, - class _BinaryOperation1, - class _BinaryOperation2, - class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, - enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp transform_reduce( - _ExecutionPolicy&& __policy, - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _Tp __init, - _BinaryOperation1 __reduce, - _BinaryOperation2 __transform) { - auto __res = std::__transform_reduce( - __policy, - std::move(__first1), - std::move(__last1), - std::move(__first2), - std::move(__init), - std::move(__reduce), - std::move(__transform)); - - if (!__res) - std::__throw_bad_alloc(); - return *std::move(__res); -} - -// This overload doesn't get a customization point because it's trivial to detect (through e.g. -// __desugars_to) when specializing the more general variant, which should always be preferred -template <class _ExecutionPolicy, - class _ForwardIterator1, - class _ForwardIterator2, - class _Tp, - enable_if_t<is_execution_policy_v<__remove_cvref_t<_ExecutionPolicy>>, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp transform_reduce( - _ExecutionPolicy&& __policy, - _ForwardIterator1 __first1, - _ForwardIterator1 __last1, - _ForwardIterator2 __first2, - _Tp __init) { - return std::transform_reduce(__policy, __first1, __last1, __first2, __init, plus{}, multiplies{}); -} - -template <class _ExecutionPolicy, - class _ForwardIterator, - class _Tp, - class _BinaryOperation, - class _UnaryOperation, - class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, - enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> -[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__remove_cvref_t<_Tp>> __transform_reduce( - _ExecutionPolicy&&, - _ForwardIterator&& __first, - _ForwardIterator&& __last, - _Tp&& __init, - _BinaryOperation&& __reduce, - _UnaryOperation&& __transform) noexcept { - using _Backend = typename __select_backend<_RawPolicy>::type; - return std::__pstl_transform_reduce<_RawPolicy>( - _Backend{}, - std::move(__first), - std::move(__last), - std::move(__init), - std::move(__reduce), - std::move(__transform)); -} - -template <class _ExecutionPolicy, - class _ForwardIterator, - class _Tp, - class _BinaryOperation, - class _UnaryOperation, - class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, - enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> -_LIBCPP_HIDE_FROM_ABI _Tp transform_reduce( - _ExecutionPolicy&& __policy, - _ForwardIterator __first, - _ForwardIterator __last, - _Tp __init, - _BinaryOperation __reduce, - _UnaryOperation __transform) { - auto __res = std::__transform_reduce( - __policy, std::move(__first), std::move(__last), std::move(__init), std::move(__reduce), std::move(__transform)); - if (!__res) - std::__throw_bad_alloc(); - return *std::move(__res); -} - -_LIBCPP_END_NAMESPACE_STD - -#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 - -_LIBCPP_POP_MACROS - -#endif // _LIBCPP___NUMERIC_PSTL_TRANSFORM_REDUCE_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__numeric/saturation_arithmetic.h b/contrib/libs/cxxsupp/libcxx/include/__numeric/saturation_arithmetic.h index 41596a0c58e..2390b42aaec 100644 --- a/contrib/libs/cxxsupp/libcxx/include/__numeric/saturation_arithmetic.h +++ b/contrib/libs/cxxsupp/libcxx/include/__numeric/saturation_arithmetic.h @@ -25,10 +25,10 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER >= 26 +#if _LIBCPP_STD_VER >= 20 template <__libcpp_integer _Tp> -_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept { +_LIBCPP_HIDE_FROM_ABI constexpr _Tp __add_sat(_Tp __x, _Tp __y) noexcept { if (_Tp __sum; !__builtin_add_overflow(__x, __y, &__sum)) return __sum; // Handle overflow @@ -46,7 +46,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept { } template <__libcpp_integer _Tp> -_LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept { +_LIBCPP_HIDE_FROM_ABI constexpr _Tp __sub_sat(_Tp __x, _Tp __y) noexcept { if (_Tp __sub; !__builtin_sub_overflow(__x, __y, &__sub)) return __sub; // Handle overflow @@ -65,7 +65,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept { } template <__libcpp_integer _Tp> -_LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept { +_LIBCPP_HIDE_FROM_ABI constexpr _Tp __mul_sat(_Tp __x, _Tp __y) noexcept { if (_Tp __mul; !__builtin_mul_overflow(__x, __y, &__mul)) return __mul; // Handle overflow @@ -81,7 +81,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept { } template <__libcpp_integer _Tp> -_LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept { +_LIBCPP_HIDE_FROM_ABI constexpr _Tp __div_sat(_Tp __x, _Tp __y) noexcept { _LIBCPP_ASSERT_UNCATEGORIZED(__y != 0, "Division by 0 is undefined"); if constexpr (__libcpp_unsigned_integer<_Tp>) { return __x / __y; @@ -94,7 +94,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept { } template <__libcpp_integer _Rp, __libcpp_integer _Tp> -_LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept { +_LIBCPP_HIDE_FROM_ABI constexpr _Rp __saturate_cast(_Tp __x) noexcept { // Saturation is impossible edge case when ((min _Rp) < (min _Tp) && (max _Rp) > (max _Tp)) and it is expected to be // optimized out by the compiler. @@ -107,6 +107,35 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept { return static_cast<_Rp>(__x); } +#endif // _LIBCPP_STD_VER >= 20 + +#if _LIBCPP_STD_VER >= 26 + +template <__libcpp_integer _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept { + return std::__add_sat(__x, __y); +} + +template <__libcpp_integer _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept { + return std::__sub_sat(__x, __y); +} + +template <__libcpp_integer _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept { + return std::__mul_sat(__x, __y); +} + +template <__libcpp_integer _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept { + return std::__div_sat(__x, __y); +} + +template <__libcpp_integer _Rp, __libcpp_integer _Tp> +_LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept { + return std::__saturate_cast<_Rp>(__x); +} + #endif // _LIBCPP_STD_VER >= 26 _LIBCPP_END_NAMESPACE_STD |