Commit 0ebec4c
Fix set::min()/max() comparator bug and non-const operator[] (#32)
* Fix set::min()/max() comparator bug and non-const operator[] (#28)
set::min()/max() used std::min_element/std::max_element, which rank by
operator< instead of the set's TCompare. For sets with a custom comparator
this returned the wrong element, required operator< even when a comparator
was supplied, and was O(n). They now return *begin() / *std::prev(end()),
which respects the comparator and is O(1).
The non-const set::operator[] did `auto it = std::advance(begin(), index)`,
but std::advance returns void, so the overload failed to compile whenever
instantiated (subscripting a non-const set). It now advances an iterator in
place, matching the const overload, and works on both C++11 and C++17.
Added tests: min/max with a comparator that differs from operator<
(descending int comparator), and non-const subscripting.
* CI: pin Windows runner to windows-2022 for VS 2022 generator
GitHub's windows-latest image no longer provides the
"Visual Studio 17 2022" generator, so CMake configure failed with
"could not find any instance of Visual Studio" before compiling.
Pin the Windows matrix entries to windows-2022.
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 764adeb commit 0ebec4c
3 files changed
Lines changed: 44 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
606 | 606 | | |
607 | 607 | | |
608 | 608 | | |
609 | | - | |
610 | | - | |
611 | | - | |
| 609 | + | |
| 610 | + | |
612 | 611 | | |
613 | | - | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
614 | 616 | | |
615 | 617 | | |
616 | 618 | | |
| |||
627 | 629 | | |
628 | 630 | | |
629 | 631 | | |
630 | | - | |
631 | | - | |
632 | | - | |
| 632 | + | |
| 633 | + | |
633 | 634 | | |
634 | | - | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
635 | 639 | | |
636 | 640 | | |
637 | 641 | | |
| |||
1102 | 1106 | | |
1103 | 1107 | | |
1104 | 1108 | | |
1105 | | - | |
1106 | | - | |
1107 | | - | |
1108 | | - | |
1109 | | - | |
1110 | 1109 | | |
1111 | | - | |
1112 | | - | |
1113 | | - | |
| 1110 | + | |
1114 | 1111 | | |
1115 | | - | |
1116 | 1112 | | |
1117 | 1113 | | |
1118 | 1114 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
335 | 364 | | |
336 | 365 | | |
337 | 366 | | |
| |||
0 commit comments