summaryrefslogtreecommitdiff
path: root/libcxx/include/set
AgeCommit message (Collapse)Author
2025-11-12[libc++] Optimize __tree copy/move constructor/assignment with allocator ↵Nikolas Klauser
(#163558) This patch applies the same optimization as implemented in #151304 to the overloads taking an allocator as the second argument. Apple M4: ``` Benchmark old new Difference % Difference ----------------------------------------------------------- -------------- -------------- ------------ -------------- std::map<int,_int>::ctor(&&,_different_allocs)/0 14.59 12.78 -1.81 -12.41% std::map<int,_int>::ctor(&&,_different_allocs)/1024 16407.05 6265.11 -10141.94 -61.81% std::map<int,_int>::ctor(&&,_different_allocs)/32 395.99 199.76 -196.23 -49.56% std::map<int,_int>::ctor(&&,_different_allocs)/8192 141478.67 53767.84 -87710.83 -62.00% std::map<int,_int>::ctor(const&,_alloc)/0 12.83 12.71 -0.12 -0.94% std::map<int,_int>::ctor(const&,_alloc)/1024 9979.71 7849.11 -2130.59 -21.35% std::map<int,_int>::ctor(const&,_alloc)/32 283.82 266.05 -17.77 -6.26% std::map<int,_int>::ctor(const&,_alloc)/8192 81418.63 63190.41 -18228.21 -22.39% std::map<std::string,_int>::ctor(&&,_different_allocs)/0 14.58 12.68 -1.90 -13.00% std::map<std::string,_int>::ctor(&&,_different_allocs)/1024 19513.56 7806.04 -11707.52 -60.00% std::map<std::string,_int>::ctor(&&,_different_allocs)/32 477.80 247.28 -230.52 -48.25% std::map<std::string,_int>::ctor(&&,_different_allocs)/8192 504558.78 69592.21 -434966.56 -86.21% std::map<std::string,_int>::ctor(const&,_alloc)/0 12.64 12.60 -0.04 -0.33% std::map<std::string,_int>::ctor(const&,_alloc)/1024 43198.53 37220.54 -5977.99 -13.84% std::map<std::string,_int>::ctor(const&,_alloc)/32 928.39 867.03 -61.36 -6.61% std::map<std::string,_int>::ctor(const&,_alloc)/8192 461313.81 389200.82 -72112.99 -15.63% ```
2025-11-02[libc++] Remove a few unused includes (#165687)Nikolas Klauser
2025-10-09[libc++] Optimize {set,map}::{lower,upper}_bound (#161366)Nikolas Klauser
Apple M4: ``` Benchmark Baseline Candidate Difference % Difference --------------------------------------------------------------------------------------------- ---------- ----------- ------------ -------------- std::map<int,_int>::lower_bound(key)_(existent)/0 0.01 0.01 -0.00 -25.78 std::map<int,_int>::lower_bound(key)_(existent)/1024 7.94 4.28 -3.66 -46.09 std::map<int,_int>::lower_bound(key)_(existent)/32 2.73 1.69 -1.03 -37.89 std::map<int,_int>::lower_bound(key)_(existent)/8192 11.63 5.52 -6.11 -52.55 std::map<int,_int>::lower_bound(key)_(non-existent)/0 0.28 0.28 -0.00 -1.35 std::map<int,_int>::lower_bound(key)_(non-existent)/1024 17.21 7.63 -9.58 -55.67 std::map<int,_int>::lower_bound(key)_(non-existent)/32 4.71 3.26 -1.45 -30.71 std::map<int,_int>::lower_bound(key)_(non-existent)/8192 26.82 10.58 -16.24 -60.55 std::map<int,_int>::upper_bound(key)_(existent)/0 0.01 0.01 0.00 20.62 std::map<int,_int>::upper_bound(key)_(existent)/1024 7.93 3.61 -4.32 -54.49 std::map<int,_int>::upper_bound(key)_(existent)/32 2.83 1.98 -0.85 -30.01 std::map<int,_int>::upper_bound(key)_(existent)/8192 11.69 5.72 -5.97 -51.06 std::map<int,_int>::upper_bound(key)_(non-existent)/0 0.28 0.28 -0.00 -1.36 std::map<int,_int>::upper_bound(key)_(non-existent)/1024 17.21 8.00 -9.21 -53.53 std::map<int,_int>::upper_bound(key)_(non-existent)/32 4.70 2.93 -1.78 -37.76 std::map<int,_int>::upper_bound(key)_(non-existent)/8192 26.54 11.18 -15.36 -57.89 std::map<std::string,_int>::lower_bound(key)_(existent)/0 0.04 0.04 -0.00 -3.26 std::map<std::string,_int>::lower_bound(key)_(existent)/1024 27.46 26.25 -1.22 -4.43 std::map<std::string,_int>::lower_bound(key)_(existent)/32 19.17 15.71 -3.46 -18.07 std::map<std::string,_int>::lower_bound(key)_(existent)/8192 35.33 35.03 -0.30 -0.84 std::map<std::string,_int>::lower_bound(key)_(non-existent)/0 0.27 0.27 -0.00 -1.45 std::map<std::string,_int>::lower_bound(key)_(non-existent)/1024 24.88 24.17 -0.70 -2.83 std::map<std::string,_int>::lower_bound(key)_(non-existent)/32 11.67 11.63 -0.04 -0.32 std::map<std::string,_int>::lower_bound(key)_(non-existent)/8192 31.81 32.33 0.52 1.64 std::map<std::string,_int>::upper_bound(key)_(existent)/0 0.04 0.04 -0.00 -2.22 std::map<std::string,_int>::upper_bound(key)_(existent)/1024 29.91 26.51 -3.40 -11.38 std::map<std::string,_int>::upper_bound(key)_(existent)/32 19.69 17.74 -1.95 -9.92 std::map<std::string,_int>::upper_bound(key)_(existent)/8192 32.55 35.24 2.69 8.25 std::map<std::string,_int>::upper_bound(key)_(non-existent)/0 0.27 0.27 -0.00 -1.74 std::map<std::string,_int>::upper_bound(key)_(non-existent)/1024 23.87 26.77 2.91 12.18 std::map<std::string,_int>::upper_bound(key)_(non-existent)/32 11.44 11.81 0.37 3.24 std::map<std::string,_int>::upper_bound(key)_(non-existent)/8192 33.02 32.59 -0.43 -1.29 std::set<int>::lower_bound(key)_(existent)/0 0.01 0.01 0.00 0.48 std::set<int>::lower_bound(key)_(existent)/1024 7.83 4.21 -3.62 -46.23 std::set<int>::lower_bound(key)_(existent)/32 2.74 1.68 -1.06 -38.81 std::set<int>::lower_bound(key)_(existent)/8192 22.75 11.12 -11.63 -51.12 std::set<int>::lower_bound(key)_(non-existent)/0 0.28 0.27 -0.01 -3.52 std::set<int>::lower_bound(key)_(non-existent)/1024 17.15 8.40 -8.75 -51.03 std::set<int>::lower_bound(key)_(non-existent)/32 4.63 2.50 -2.13 -46.03 std::set<int>::lower_bound(key)_(non-existent)/8192 28.88 11.05 -17.82 -61.72 std::set<int>::upper_bound(key)_(existent)/0 0.01 0.01 -0.00 -7.79 std::set<int>::upper_bound(key)_(existent)/1024 7.80 3.63 -4.16 -53.42 std::set<int>::upper_bound(key)_(existent)/32 2.81 1.90 -0.91 -32.44 std::set<int>::upper_bound(key)_(existent)/8192 21.93 11.35 -10.58 -48.26 std::set<int>::upper_bound(key)_(non-existent)/0 0.28 0.27 -0.01 -3.81 std::set<int>::upper_bound(key)_(non-existent)/1024 16.76 7.38 -9.38 -55.98 std::set<int>::upper_bound(key)_(non-existent)/32 4.58 3.10 -1.48 -32.31 std::set<int>::upper_bound(key)_(non-existent)/8192 26.95 10.70 -16.25 -60.29 std::set<std::string>::lower_bound(key)_(existent)/0 0.04 0.04 0.00 0.02 std::set<std::string>::lower_bound(key)_(existent)/1024 28.08 27.04 -1.04 -3.71 std::set<std::string>::lower_bound(key)_(existent)/32 17.53 16.94 -0.58 -3.34 std::set<std::string>::lower_bound(key)_(existent)/8192 32.79 33.28 0.49 1.49 std::set<std::string>::lower_bound(key)_(non-existent)/0 0.28 0.28 -0.00 -0.06 std::set<std::string>::lower_bound(key)_(non-existent)/1024 25.23 24.38 -0.85 -3.38 std::set<std::string>::lower_bound(key)_(non-existent)/32 11.45 11.68 0.24 2.07 std::set<std::string>::lower_bound(key)_(non-existent)/8192 32.30 36.80 4.50 13.95 std::set<std::string>::upper_bound(key)_(existent)/0 0.04 0.04 -0.00 -0.14 std::set<std::string>::upper_bound(key)_(existent)/1024 26.71 26.37 -0.34 -1.27 std::set<std::string>::upper_bound(key)_(existent)/32 20.07 19.06 -1.02 -5.06 std::set<std::string>::upper_bound(key)_(existent)/8192 36.69 35.50 -1.19 -3.25 std::set<std::string>::upper_bound(key)_(non-existent)/0 0.28 0.28 -0.00 -0.16 std::set<std::string>::upper_bound(key)_(non-existent)/1024 24.48 24.90 0.42 1.73 std::set<std::string>::upper_bound(key)_(non-existent)/32 11.68 11.77 0.09 0.77 std::set<std::string>::upper_bound(key)_(non-existent)/8192 33.16 34.12 0.96 2.89 ```
2025-10-07[libc++] Make the naming of the iterator_traits aliases consistent (#161661)Nikolas Klauser
This renames all the `iterator_traits` alises to be `__iterator_<type-name>`. e.g `iterator_traits<T>::value_type` will be `__iterator_value_type<T>`.
2025-09-24[libc++][NFC] Refactor __is_allocator to be a variable template (#159584)Nikolas Klauser
2025-09-22[libc++][NFC] Reformat some deduction guides (#160085)Nikolas Klauser
They're not formatted correctly anymore, since clang-format was updated.
2025-09-03[libc++] Optimize {map,set}::insert(InputIterator, InputIterator) (#154703)Nikolas Klauser
``` ---------------------------------------------------------------------------------------------------------------------------- Benchmark old new ---------------------------------------------------------------------------------------------------------------------------- std::map<int, int>::ctor(iterator, iterator) (unsorted sequence)/0 14.2 ns 14.8 ns std::map<int, int>::ctor(iterator, iterator) (unsorted sequence)/32 519 ns 404 ns std::map<int, int>::ctor(iterator, iterator) (unsorted sequence)/1024 52460 ns 36242 ns std::map<int, int>::ctor(iterator, iterator) (unsorted sequence)/8192 724222 ns 706496 ns std::map<int, int>::ctor(iterator, iterator) (sorted sequence)/0 14.2 ns 14.7 ns std::map<int, int>::ctor(iterator, iterator) (sorted sequence)/32 429 ns 349 ns std::map<int, int>::ctor(iterator, iterator) (sorted sequence)/1024 23601 ns 14734 ns std::map<int, int>::ctor(iterator, iterator) (sorted sequence)/8192 267753 ns 112155 ns std::map<int, int>::insert(iterator, iterator) (all new keys)/0 434 ns 448 ns std::map<int, int>::insert(iterator, iterator) (all new keys)/32 950 ns 963 ns std::map<int, int>::insert(iterator, iterator) (all new keys)/1024 27205 ns 25344 ns std::map<int, int>::insert(iterator, iterator) (all new keys)/8192 294248 ns 280713 ns std::map<int, int>::insert(iterator, iterator) (half new keys)/0 435 ns 449 ns std::map<int, int>::insert(iterator, iterator) (half new keys)/32 771 ns 706 ns std::map<int, int>::insert(iterator, iterator) (half new keys)/1024 30841 ns 17495 ns std::map<int, int>::insert(iterator, iterator) (half new keys)/8192 468807 ns 285847 ns std::map<int, int>::insert(iterator, iterator) (product_iterator from same type)/0 449 ns 453 ns std::map<int, int>::insert(iterator, iterator) (product_iterator from same type)/32 1021 ns 932 ns std::map<int, int>::insert(iterator, iterator) (product_iterator from same type)/1024 29796 ns 19518 ns std::map<int, int>::insert(iterator, iterator) (product_iterator from same type)/8192 345688 ns 153966 ns std::map<int, int>::insert(iterator, iterator) (product_iterator from zip_view)/0 449 ns 450 ns std::map<int, int>::insert(iterator, iterator) (product_iterator from zip_view)/32 1026 ns 807 ns std::map<int, int>::insert(iterator, iterator) (product_iterator from zip_view)/1024 31632 ns 15573 ns std::map<int, int>::insert(iterator, iterator) (product_iterator from zip_view)/8192 303024 ns 128946 ns std::map<int, int>::erase(iterator, iterator) (erase half the container)/0 447 ns 452 ns std::map<int, int>::erase(iterator, iterator) (erase half the container)/32 687 ns 710 ns std::map<int, int>::erase(iterator, iterator) (erase half the container)/1024 8604 ns 8581 ns std::map<int, int>::erase(iterator, iterator) (erase half the container)/8192 65693 ns 67406 ns std::map<std::string, int>::ctor(iterator, iterator) (unsorted sequence)/0 15.0 ns 15.0 ns std::map<std::string, int>::ctor(iterator, iterator) (unsorted sequence)/32 2781 ns 1845 ns std::map<std::string, int>::ctor(iterator, iterator) (unsorted sequence)/1024 187999 ns 182103 ns std::map<std::string, int>::ctor(iterator, iterator) (unsorted sequence)/8192 2937242 ns 2934912 ns std::map<std::string, int>::ctor(iterator, iterator) (sorted sequence)/0 15.0 ns 15.2 ns std::map<std::string, int>::ctor(iterator, iterator) (sorted sequence)/32 1326 ns 2462 ns std::map<std::string, int>::ctor(iterator, iterator) (sorted sequence)/1024 81778 ns 72193 ns std::map<std::string, int>::ctor(iterator, iterator) (sorted sequence)/8192 1177292 ns 669152 ns std::map<std::string, int>::insert(iterator, iterator) (all new keys)/0 439 ns 454 ns std::map<std::string, int>::insert(iterator, iterator) (all new keys)/32 2483 ns 2465 ns std::map<std::string, int>::insert(iterator, iterator) (all new keys)/1024 187614 ns 188072 ns std::map<std::string, int>::insert(iterator, iterator) (all new keys)/8192 1654675 ns 1706603 ns std::map<std::string, int>::insert(iterator, iterator) (half new keys)/0 437 ns 452 ns std::map<std::string, int>::insert(iterator, iterator) (half new keys)/32 1836 ns 1820 ns std::map<std::string, int>::insert(iterator, iterator) (half new keys)/1024 114885 ns 121865 ns std::map<std::string, int>::insert(iterator, iterator) (half new keys)/8192 1151960 ns 1197318 ns std::map<std::string, int>::insert(iterator, iterator) (product_iterator from same type)/0 438 ns 455 ns std::map<std::string, int>::insert(iterator, iterator) (product_iterator from same type)/32 1599 ns 1614 ns std::map<std::string, int>::insert(iterator, iterator) (product_iterator from same type)/1024 95935 ns 82159 ns std::map<std::string, int>::insert(iterator, iterator) (product_iterator from same type)/8192 776480 ns 941043 ns std::map<std::string, int>::insert(iterator, iterator) (product_iterator from zip_view)/0 435 ns 462 ns std::map<std::string, int>::insert(iterator, iterator) (product_iterator from zip_view)/32 1723 ns 1550 ns std::map<std::string, int>::insert(iterator, iterator) (product_iterator from zip_view)/1024 107096 ns 92850 ns std::map<std::string, int>::insert(iterator, iterator) (product_iterator from zip_view)/8192 893976 ns 775046 ns std::map<std::string, int>::erase(iterator, iterator) (erase half the container)/0 436 ns 453 ns std::map<std::string, int>::erase(iterator, iterator) (erase half the container)/32 775 ns 824 ns std::map<std::string, int>::erase(iterator, iterator) (erase half the container)/1024 20241 ns 20454 ns std::map<std::string, int>::erase(iterator, iterator) (erase half the container)/8192 139038 ns 138032 ns std::set<int>::ctor(iterator, iterator) (unsorted sequence)/0 14.8 ns 14.7 ns std::set<int>::ctor(iterator, iterator) (unsorted sequence)/32 468 ns 426 ns std::set<int>::ctor(iterator, iterator) (unsorted sequence)/1024 54289 ns 39028 ns std::set<int>::ctor(iterator, iterator) (unsorted sequence)/8192 738438 ns 695720 ns std::set<int>::ctor(iterator, iterator) (sorted sequence)/0 14.7 ns 14.6 ns std::set<int>::ctor(iterator, iterator) (sorted sequence)/32 478 ns 391 ns std::set<int>::ctor(iterator, iterator) (sorted sequence)/1024 24017 ns 13905 ns std::set<int>::ctor(iterator, iterator) (sorted sequence)/8192 267862 ns 111378 ns std::set<int>::insert(iterator, iterator) (all new keys)/0 458 ns 450 ns std::set<int>::insert(iterator, iterator) (all new keys)/32 1066 ns 956 ns std::set<int>::insert(iterator, iterator) (all new keys)/1024 29190 ns 25212 ns std::set<int>::insert(iterator, iterator) (all new keys)/8192 320441 ns 279602 ns std::set<int>::insert(iterator, iterator) (half new keys)/0 454 ns 453 ns std::set<int>::insert(iterator, iterator) (half new keys)/32 816 ns 709 ns std::set<int>::insert(iterator, iterator) (half new keys)/1024 32072 ns 17074 ns std::set<int>::insert(iterator, iterator) (half new keys)/8192 403386 ns 286202 ns std::set<int>::erase(iterator, iterator) (erase half the container)/0 451 ns 452 ns std::set<int>::erase(iterator, iterator) (erase half the container)/32 710 ns 703 ns std::set<int>::erase(iterator, iterator) (erase half the container)/1024 8261 ns 8499 ns std::set<int>::erase(iterator, iterator) (erase half the container)/8192 64466 ns 67343 ns std::set<std::string>::ctor(iterator, iterator) (unsorted sequence)/0 15.2 ns 15.0 ns std::set<std::string>::ctor(iterator, iterator) (unsorted sequence)/32 3069 ns 3005 ns std::set<std::string>::ctor(iterator, iterator) (unsorted sequence)/1024 189552 ns 180933 ns std::set<std::string>::ctor(iterator, iterator) (unsorted sequence)/8192 2887579 ns 2691678 ns std::set<std::string>::ctor(iterator, iterator) (sorted sequence)/0 15.1 ns 14.9 ns std::set<std::string>::ctor(iterator, iterator) (sorted sequence)/32 2611 ns 2514 ns std::set<std::string>::ctor(iterator, iterator) (sorted sequence)/1024 91581 ns 78727 ns std::set<std::string>::ctor(iterator, iterator) (sorted sequence)/8192 1192640 ns 1158959 ns std::set<std::string>::insert(iterator, iterator) (all new keys)/0 452 ns 457 ns std::set<std::string>::insert(iterator, iterator) (all new keys)/32 2530 ns 2544 ns std::set<std::string>::insert(iterator, iterator) (all new keys)/1024 195352 ns 179614 ns std::set<std::string>::insert(iterator, iterator) (all new keys)/8192 1737890 ns 1749615 ns std::set<std::string>::insert(iterator, iterator) (half new keys)/0 451 ns 454 ns std::set<std::string>::insert(iterator, iterator) (half new keys)/32 1949 ns 1766 ns std::set<std::string>::insert(iterator, iterator) (half new keys)/1024 128853 ns 109467 ns std::set<std::string>::insert(iterator, iterator) (half new keys)/8192 1233077 ns 1177289 ns std::set<std::string>::erase(iterator, iterator) (erase half the container)/0 450 ns 451 ns std::set<std::string>::erase(iterator, iterator) (erase half the container)/32 809 ns 812 ns std::set<std::string>::erase(iterator, iterator) (erase half the container)/1024 21736 ns 21922 ns std::set<std::string>::erase(iterator, iterator) (erase half the container)/8192 135884 ns 133228 ns ``` Fixes #154650
2025-08-27Reapply "[libc++] Refactor key extraction for __hash_table and __tree ↵Nikolas Klauser
(#154512)" (#155565) The original PR has been reverted because of an LLDB test failure. This patch now works around the test failure by simply allowing the new symbols to show up in a stack trace. This reverts commit 72c04bb882ad70230bce309c3013d9cc2c99e9a7. Original commit message: This patch replaces `__can_extract_key` with an overload set to try to extract the key. This simplifies the code, since we don't need to have separate overload sets for the unordered and associative containers. It also allows extending the set of extraction cases more easily, since we have a single place to define how the key is extracted.
2025-08-26Revert "[libc++] Refactor key extraction for __hash_table and __tree (#154512)"Aiden Grossman
This reverts commit af1f06e41b05c267480f1629dc0fcdf18f3b59f6. This is causing some build failures in premerge as some of the LLDB tests fail.
2025-08-26[libc++] Refactor key extraction for __hash_table and __tree (#154512)Nikolas Klauser
This patch replaces `__can_extract_key` with an overload set to try to extract the key. This simplifies the code, since we don't need to have separate overload sets for the unordered and associative containers. It also allows extending the set of extraction cases more easily, since we have a single place to define how the key is extracted.
2025-08-22[libc++] Optimize multi{map,set}::insert(InputIterator, InputIterator) (#152691)Nikolas Klauser
2025-08-22[libc++][NFC] Simplify the special member functions of the node containers ↵Nikolas Klauser
(#154707) This patch does two things: - Remove exception specifications of `= default`ed special member functions - `= default` special member functions The first part is NFC because the explicit specification does exactly the same as the implicit specification. The second is NFC because it does exactly what the `= default`ed special member does.
2025-08-19[libc++] Make `std::__tree_node` member private to prepare for UB removal ↵Vinay Deshmukh
(#154225) Prepare for: https://github.com/llvm/llvm-project/pull/153908#discussion_r2281756219
2025-08-07[libc++] Remove unnecessary friend declarations from <__tree> (#152133)Nikolas Klauser
Removing the unnecessary friend declarations from `<__tree>` also removes the need for forward declaration headers for `map` and `set`, which this patch also removes.
2025-08-05[libc++] Optimize copy construction and assignment of __tree (#151304)Nikolas Klauser
``` ---------------------------------------------------------------------------------------------------------- Benchmark old new ---------------------------------------------------------------------------------------------------------- std::map<int, int>::ctor(const&)/0 15.5 ns 14.9 ns std::map<int, int>::ctor(const&)/32 474 ns 321 ns std::map<int, int>::ctor(const&)/1024 24591 ns 11101 ns std::map<int, int>::ctor(const&)/8192 236153 ns 98868 ns std::map<std::string, int>::ctor(const&)/0 15.2 ns 14.9 ns std::map<std::string, int>::ctor(const&)/32 2673 ns 2340 ns std::map<std::string, int>::ctor(const&)/1024 115354 ns 86088 ns std::map<std::string, int>::ctor(const&)/8192 1298510 ns 626876 ns std::map<int, int>::operator=(const&) (into cleared Container)/0 16.5 ns 16.1 ns std::map<int, int>::operator=(const&) (into cleared Container)/32 548 ns 323 ns std::map<int, int>::operator=(const&) (into cleared Container)/1024 28418 ns 11026 ns std::map<int, int>::operator=(const&) (into cleared Container)/8192 281827 ns 97113 ns std::map<int, int>::operator=(const&) (into populated Container)/0 2.42 ns 1.85 ns std::map<int, int>::operator=(const&) (into populated Container)/32 369 ns 73.0 ns std::map<int, int>::operator=(const&) (into populated Container)/1024 24078 ns 2322 ns std::map<int, int>::operator=(const&) (into populated Container)/8192 266537 ns 22963 ns std::map<std::string, int>::operator=(const&) (into cleared Container)/0 16.6 ns 16.2 ns std::map<std::string, int>::operator=(const&) (into cleared Container)/32 2614 ns 1622 ns std::map<std::string, int>::operator=(const&) (into cleared Container)/1024 116826 ns 63281 ns std::map<std::string, int>::operator=(const&) (into cleared Container)/8192 1316655 ns 649177 ns std::map<std::string, int>::operator=(const&) (into populated Container)/0 2.42 ns 1.89 ns std::map<std::string, int>::operator=(const&) (into populated Container)/32 1264 ns 581 ns std::map<std::string, int>::operator=(const&) (into populated Container)/1024 238826 ns 39943 ns std::map<std::string, int>::operator=(const&) (into populated Container)/8192 2412327 ns 379456 ns ``` Fixes #77658 Fixes #62571
2025-07-10[libc++] Fix insert() calling incorrect constructors (#146231)Nikolas Klauser
This fixes `insert()` calling the wrong `allocator_traits::construct` in the associative containers by removing the special handling that lead to the inconsistencty inside `__tree` and `__hash_table`.
2025-07-05[libc++] default some special members in map and set (#147081)Nikolas Klauser
We don't actually do anything special in these special member functions, so we can just `= default` them to save a bit of code.
2025-06-07[libc++] Do not call `reserve` in flat containers if underlying container is ↵Hui
user defined (#140379) This is brought up in the LWG reflector. We currently call `reserve` if the underlying container has one. But the spec does not specify what `reserve` should do for Sequence Container. So in theory if the underlying container is user defined type and it can have a function called `reserve` which does something completely different. The fix is to just call `reserve` for STL containers if it has one
2025-04-09[libc++] Remove _LIBCPP_TEMPLATE_VIS (#134885)Nikolas Klauser
The need for `_LIBCPP_TEMPLATE_VIS` has been removed in #133233.
2025-03-20[NFC][libc++] Adds (multi|)(map|set) forward declarations. (#131541)Mark de Wever
This removes duplicated forward declarations of these classes. closes: #131518
2025-02-21[libc++] Qualify calls to nullary functions like __throw_foo (#122465)Louis Dionne
This is technically not necessary in most cases to prevent issues with ADL, but let's be consistent. This allows us to remove the libcpp-qualify-declval clang-tidy check, which is now enforced by the robust-against-adl clang-tidy check.
2025-02-15[libc++] Fixes (|multi)_set spaceship operator. (#127326)Mark de Wever
The operators did not have a _Compare template arguement. The fix updates the generic container test to use allocators for all types used. No other issues were found. Fixes: #127095
2024-12-21[libc++][C++03] Use `__cxx03/` headers in C++03 mode (#109002)Nikolas Klauser
This patch implements the forwarding to frozen C++03 headers as discussed in https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc. In the RFC, we initially proposed selecting the right headers from the Clang driver, however consensus seemed to steer towards handling this in the library itself. This patch implements that direction. At a high level, the changes basically amount to making each public header look like this: ``` // inside <vector> #ifdef _LIBCPP_CXX03_LANG # include <__cxx03/vector> #else // normal <vector> content #endif ``` In most cases, public headers are simple umbrella headers so there isn't much code in the #else branch. In other cases, the #else branch contains the actual implementation of the header.
2024-12-10[libc++] Add #if 0 block to all the top-level headers (#119234)Nikolas Klauser
Including The frozen C++03 headers results in a lot of formatting changes in the main headers, so this splits these changes into a separate commit instead. This is part of https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc.
2024-10-12[libc++] Add container_traits (prework for `std::flat_map`) (#109578)Hui
This PR is extracted from https://github.com/llvm/llvm-project/pull/98643, as per code review request https://github.com/llvm/llvm-project/pull/98643#discussion_r1768967793
2024-09-16[libc++][modules] Fix missing and incorrect includes (#108850)Louis Dionne
This patch adds a large number of missing includes in the libc++ headers and the test suite. Those were found as part of the effort to move towards a mostly monolithic top-level std module.
2024-09-12[libc++][NFC] Use [[__nodiscard__]] unconditionally (#80454)Nikolas Klauser
`__has_cpp_attribute(__nodiscard__)` is always true now, so we might as well replace `_LIBCPP_NODISCARD`. It's one less macro that can result in bad diagnostics.
2024-08-30[libc++][NFC] Run clang-format on libcxx/includeLouis Dionne
This re-formats a few headers that had become out-of-sync with respect to formatting since we ran clang-format on the whole codebase. There's surprisingly few instances of it.
2024-07-07[libc++] Restore `__synth_three_way` lambda (#90398)Hristo Hristov
Restore `__synth_three_way` lambda to match the Standard. GH-57222 is done, restoring the Standard wording implementation should be possible. https://github.com/llvm/llvm-project/blob/df28d4412c1d21b0e18896c92ac77d2fac7729f1/libcxx/include/__compare/synth_three_way.h#L28 According to comment https://github.com/llvm/llvm-project/issues/59513#issuecomment-2068338762, GH-59513 is not a blocker. Co-authored-by: Hristo Hristov <zingam@outlook.com>
2024-06-25[libc++] Move allocator assertion into allocator_traits (#94750)Hui
There is code duplication in all containers that static_assert the allocator matches the allocator requirements in the spec. This check can be moved into a more centralised place.
2024-06-23[libc++][NFC] Replace _NOEXCEPT and _LIBCPP_CONSTEXPR macros with the ↵Nikolas Klauser
keywords in C++11 code (#96387)
2024-06-18[libc++][NFC] Run clang-format on libcxx/include again (#95874)Louis Dionne
As time went by, a few files have become mis-formatted w.r.t. clang-format. This was made worse by the fact that formatting was not being enforced in extensionless headers. This commit simply brings all of libcxx/include in-line with clang-format again. We might have to do this from time to time as we update our clang-format version, but frankly this is really low effort now that we've formatted everything once.
2024-06-18[libc++] Refactor<__type_traits/is_swappable.h> (#86822)Nikolas Klauser
This changes the `is_swappable` implementation to use variable templates first and basing the class templates on that. This avoids instantiating them when the `_v` versions are used, which are generally less resource intensive.
2024-06-18[libc++][NFC] Remove unnecessary parens in static_asserts (#95605)Nikolas Klauser
These were required a long time ago due to `static_assert` not actually being available in C++03. Now `static_assert` is simply mapped to `_Static_assert` in C++03, making the additional parens unnecessary.
2024-05-28[libc++] Make the __availability header a sub-header of __config (#93083)Louis Dionne
In essence, this header has always been related to configuration of the library but we didn't want to put it inside <__config> due to complexity reasons. Now that we have sub-headers in <__config>, we can move <__availability> to it and stop including it everywhere since we already obtain the required macros via <__config>.
2024-05-08[libc++][NFC] Refactor __is_transparent to be a variable template (#90865)Nikolas Klauser
2024-04-22[libc++] Remove _LIBCPP_DISABLE_NODISCARD_EXTENSIONS and refactor the tests ↵Nikolas Klauser
(#87094) This also adds a few tests that were missing.
2024-02-29[libc++] Clean up includes of <__assert> (#80091)Louis Dionne
Originally, we used __libcpp_verbose_abort to handle assertion failures. That function was declared from all public headers. Since we don't use that mechanism anymore, we don't need to declare __libcpp_verbose_abort from all public headers, and we can clean up a lot of unnecessary includes. This patch also moves the definition of the various assertion categories to the <__assert> header, since we now rely on regular IWYU for these assertion macros. rdar://105510916
2024-01-25[libc++] Fix missing and incorrect push/pop macros (#79204)Louis Dionne
We recently noticed that the unwrap_iter.h file was pushing macros, but it was pushing them again instead of popping them at the end of the file. This led to libc++ basically swallowing any custom definition of these macros in user code: #define min HELLO #include <algorithm> // min is not HELLO anymore, it's not defined While investigating this issue, I noticed that our push/pop pragmas were actually entirely wrong too. Indeed, instead of pushing macros like `move`, we'd push `move(int, int)` in the pragma, which is not a valid macro name. As a result, we would not actually push macros like `move` -- instead we'd simply undefine them. This led to the following code not working: #define move HELLO #include <algorithm> // move is not HELLO anymore Fixing the pragma push/pop incantations led to a cascade of issues because we use identifiers like `move` in a large number of places, and all of these headers would now need to do the push/pop dance. This patch fixes all these issues. First, it adds a check that we don't swallow important names like min, max, move or refresh as explained above. This is done by augmenting the existing system_reserved_names.gen.py test to also check that the macros are what we expect after including each header. Second, it fixes the push/pop pragmas to work properly and adds missing pragmas to all the files I could detect a failure in via the newly added test. rdar://121365472
2024-01-05[libc++][hardening] Categorize more assertions. (#75918)Konstantin Varlamov
Also introduce `_LIBCPP_ASSERT_PEDANTIC` for assertions violating which results in a no-op or other benign behavior, but which may nevertheless indicate a bug in the invoking code.
2023-12-18[libc++] Format the code base (#74334)Louis Dionne
This patch runs clang-format on all of libcxx/include and libcxx/src, in accordance with the RFC discussed at [1]. Follow-up patches will format the benchmarks, the test suite and remaining parts of the code. I'm splitting this one into its own patch so the diff is a bit easier to review. This patch was generated with: find libcxx/include libcxx/src -type f \ | grep -v 'module.modulemap.in' \ | grep -v 'CMakeLists.txt' \ | grep -v 'README.txt' \ | grep -v 'libcxx.imp' \ | grep -v '__config_site.in' \ | xargs clang-format -i A Git merge driver is available in libcxx/utils/clang-format-merge-driver.sh to help resolve merge and rebase issues across these formatting changes. [1]: https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all
2023-12-05[libc++] Replace uses of _VSTD:: by std:: (#74331)Louis Dionne
As part of the upcoming clang-formatting of libc++, this patch performs the long desired removal of the _VSTD macro. See https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all for the clang-format proposal.
2023-12-04[libc++] Rename _LIBCPP_INLINE_VISIBILITY to _LIBCPP_HIDE_FROM_ABI (#74095)Louis Dionne
In preparation for running clang-format on the whole code base, we are also removing mentions of the legacy _LIBCPP_INLINE_VISIBILITY macro in favor of the newer _LIBCPP_HIDE_FROM_ABI. We're still leaving the definition of _LIBCPP_INLINE_VISIBILITY to avoid creating needless breakage in case some older patches are checked-in with mentions of the old macro. After we branch for LLVM 18, we can do another pass to clean up remaining uses of the macro that might have gotten introduced by mistake (if any) and remove the macro itself at the same time. This is just a minor convenience to smooth out the transition as much as possible. See https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all for the clang-format proposal.
2023-10-29[libc++] Remove a few transitive includes (#70553)philnik777
2023-08-15[libc++][NFC] Refactor return type enable_ifs to defaulted template argumentsNikolas Klauser
This brings most of the enable_ifs in libc++ to the same style. It also has the nice side-effect of reducing the size of names of these symbols, since the depedent return type is shorter. Reviewed By: #libc, ldionne Spies: ldionne, libcxx-commits Differential Revision: https://reviews.llvm.org/D157736
2023-07-18[libc++][ranges] Implement the changes to node-based containers from P1206 ↵varconst
(`ranges::to`): - add the `from_range_t` constructors and the related deduction guides; - add the `insert_range`/`assign_range`/etc. member functions. (Note: this patch is split from https://reviews.llvm.org/D142335) Differential Revision: https://reviews.llvm.org/D149830
2023-06-28[libc++][hardening][NFC] Introduce `_LIBCPP_ASSERT_UNCATEGORIZED`.varconst
Replace most uses of `_LIBCPP_ASSERT` with `_LIBCPP_ASSERT_UNCATEGORIZED`. This is done as a prerequisite to introducing hardened mode to libc++. The idea is to make enabling assertions an opt-in with (somewhat) fine-grained controls over which categories of assertions are enabled. The vast majority of assertions are currently uncategorized; the new macro will allow turning on `_LIBCPP_ASSERT` (the underlying mechanism for all kinds of assertions) without enabling all the uncategorized assertions (in the future; this patch preserves the current behavior). Differential Revision: https://reviews.llvm.org/D153816
2023-06-20[libc++] Add incomplete availability markup for std::pmrLouis Dionne
This fixes rdar://110330781, which asked for the feature-test macro for std::pmr to take into account the deployment target. It doesn't fix https://llvm.org/PR62212, though, because the availability markup itself must be disabled until some Clang bugs have been fixed. This is pretty vexing, however at least everything should work once those Clang bugs have been fixed. In the meantime, this patch at least adds the required markup (as disabled) and ensures that the feature-test macro for std::pmr is aware of the deployment target requirement. Differential Revision: https://reviews.llvm.org/D135813
2023-05-29[libc++][spaceship] Implement `operator<=>` for `multiset` and `set`Hristo Hristov
Implements parts of P1614R2 Implemented `operator<=>` for `multiset` and `set` Reviewed By: #libc, Mordante Differential Revision: https://reviews.llvm.org/D148416
2023-05-18[libc++][NFC] Rename iterator category checks to make it obvious that they ↵Nikolas Klauser
check //only// the iterator category We plan to add concepts for checking that iterators actually provide what they claim to. This is to avoid people thinking that these type traits actually check the iterator requirements in more detail. Reviewed By: ldionne, #libc Spies: Mordante, libcxx-commits, wenlei Differential Revision: https://reviews.llvm.org/D150801