28
28
#include < __cstddef/byte.h>
29
29
#include < __cstddef/ptrdiff_t.h>
30
30
#include < __flat_map/sorted_unique.h>
31
+ #include < __flat_set/ra_iterator.h>
31
32
#include < __functional/invoke.h>
32
33
#include < __functional/is_transparent.h>
33
34
#include < __functional/operations.h>
55
56
#include < __type_traits/is_allocator.h>
56
57
#include < __type_traits/is_nothrow_constructible.h>
57
58
#include < __type_traits/is_same.h>
59
+ #include " __type_traits/remove_reference.h"
60
+ #include < __utility/as_const.h>
58
61
#include < __utility/exception_guard.h>
59
62
#include < __utility/move.h>
60
63
#include < __utility/pair.h>
@@ -81,6 +84,8 @@ class flat_set {
81
84
static_assert (is_same_v<_Key, typename _KeyContainer::value_type>);
82
85
static_assert (!is_same_v<_KeyContainer, std::vector<bool >>, " vector<bool> is not a sequence container" );
83
86
87
+ using __key_iterator _LIBCPP_NODEBUG = typename _KeyContainer::const_iterator;
88
+
84
89
public:
85
90
// types
86
91
using key_type = _Key;
@@ -91,7 +96,7 @@ class flat_set {
91
96
using const_reference = const value_type&;
92
97
using size_type = typename _KeyContainer::size_type;
93
98
using difference_type = typename _KeyContainer::difference_type;
94
- using iterator = typename _KeyContainer::const_iterator;
99
+ using iterator = __ra_iterator<flat_set, typename _KeyContainer::const_iterator> ;
95
100
using const_iterator = iterator;
96
101
using reverse_iterator = std::reverse_iterator<iterator>;
97
102
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
@@ -328,10 +333,10 @@ class flat_set {
328
333
}
329
334
330
335
// iterators
331
- _LIBCPP_HIDE_FROM_ABI iterator begin () noexcept { return __keys_.begin (); }
332
- _LIBCPP_HIDE_FROM_ABI const_iterator begin () const noexcept { return __keys_.begin (); }
333
- _LIBCPP_HIDE_FROM_ABI iterator end () noexcept { return __keys_.end (); }
334
- _LIBCPP_HIDE_FROM_ABI const_iterator end () const noexcept { return __keys_.end (); }
336
+ _LIBCPP_HIDE_FROM_ABI iterator begin () noexcept { return iterator ( std::as_const ( __keys_) .begin () ); }
337
+ _LIBCPP_HIDE_FROM_ABI const_iterator begin () const noexcept { return const_iterator ( __keys_.begin () ); }
338
+ _LIBCPP_HIDE_FROM_ABI iterator end () noexcept { return iterator ( std::as_const ( __keys_) .end () ); }
339
+ _LIBCPP_HIDE_FROM_ABI const_iterator end () const noexcept { return const_iterator ( __keys_.end () ); }
335
340
336
341
_LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin () noexcept { return reverse_iterator (end ()); }
337
342
_LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin () const noexcept { return const_reverse_iterator (end ()); }
@@ -442,9 +447,9 @@ class flat_set {
442
447
443
448
_LIBCPP_HIDE_FROM_ABI iterator erase (iterator __position) {
444
449
auto __on_failure = std::__make_exception_guard ([&]() noexcept { clear () /* noexcept */ ; });
445
- auto __key_iter = __keys_.erase (__position);
450
+ auto __key_iter = __keys_.erase (__position. __base () );
446
451
__on_failure.__complete ();
447
- return __key_iter;
452
+ return iterator ( __key_iter) ;
448
453
}
449
454
450
455
// The following overload is the same as the iterator overload
@@ -471,9 +476,9 @@ class flat_set {
471
476
472
477
_LIBCPP_HIDE_FROM_ABI iterator erase (const_iterator __first, const_iterator __last) {
473
478
auto __on_failure = std::__make_exception_guard ([&]() noexcept { clear () /* noexcept */ ; });
474
- auto __key_it = __keys_.erase (__first, __last);
479
+ auto __key_it = __keys_.erase (__first. __base () , __last. __base () );
475
480
__on_failure.__complete ();
476
- return __key_it;
481
+ return iterator ( std::move ( __key_it)) ;
477
482
}
478
483
479
484
_LIBCPP_HIDE_FROM_ABI void swap (flat_set& __y) noexcept {
@@ -525,43 +530,43 @@ class flat_set {
525
530
}
526
531
527
532
_LIBCPP_HIDE_FROM_ABI iterator lower_bound (const key_type& __x) {
528
- return ranges::lower_bound (__keys_, __x, __compare_);
533
+ return iterator ( ranges::lower_bound (std::as_const ( __keys_) , __x, __compare_) );
529
534
}
530
535
531
536
_LIBCPP_HIDE_FROM_ABI const_iterator lower_bound (const key_type& __x) const {
532
- return ranges::lower_bound (__keys_, __x, __compare_);
537
+ return const_iterator ( ranges::lower_bound (__keys_, __x, __compare_) );
533
538
}
534
539
535
540
template <class _Kp >
536
541
requires __is_transparent_v<_Compare>
537
542
_LIBCPP_HIDE_FROM_ABI iterator lower_bound (const _Kp& __x) {
538
- return ranges::lower_bound (__keys_, __x, __compare_);
543
+ return iterator ( ranges::lower_bound (std::as_const ( __keys_) , __x, __compare_) );
539
544
}
540
545
541
546
template <class _Kp >
542
547
requires __is_transparent_v<_Compare>
543
548
_LIBCPP_HIDE_FROM_ABI const_iterator lower_bound (const _Kp& __x) const {
544
- return ranges::lower_bound (__keys_, __x, __compare_);
549
+ return const_iterator ( ranges::lower_bound (__keys_, __x, __compare_) );
545
550
}
546
551
547
552
_LIBCPP_HIDE_FROM_ABI iterator upper_bound (const key_type& __x) {
548
- return ranges::upper_bound (__keys_, __x, __compare_);
553
+ return iterator ( ranges::upper_bound (std::as_const ( __keys_) , __x, __compare_) );
549
554
}
550
555
551
556
_LIBCPP_HIDE_FROM_ABI const_iterator upper_bound (const key_type& __x) const {
552
- return ranges::upper_bound (__keys_, __x, __compare_);
557
+ return const_iterator ( ranges::upper_bound (__keys_, __x, __compare_) );
553
558
}
554
559
555
560
template <class _Kp >
556
561
requires __is_transparent_v<_Compare>
557
562
_LIBCPP_HIDE_FROM_ABI iterator upper_bound (const _Kp& __x) {
558
- return ranges::upper_bound (__keys_, __x, __compare_);
563
+ return iterator ( ranges::upper_bound (std::as_const ( __keys_) , __x, __compare_) );
559
564
}
560
565
561
566
template <class _Kp >
562
567
requires __is_transparent_v<_Compare>
563
568
_LIBCPP_HIDE_FROM_ABI const_iterator upper_bound (const _Kp& __x) const {
564
- return ranges::upper_bound (__keys_, __x, __compare_);
569
+ return const_iterator ( ranges::upper_bound (__keys_, __x, __compare_) );
565
570
}
566
571
567
572
_LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range (const key_type& __x) {
@@ -661,12 +666,13 @@ class flat_set {
661
666
662
667
template <class _Self , class _Kp >
663
668
_LIBCPP_HIDE_FROM_ABI static auto __equal_range_impl (_Self&& __self, const _Kp& __key) {
664
- auto __it = ranges::lower_bound (__self.__keys_ , __key, __self.__compare_ );
665
- auto __last = __self.__keys_ .end ();
669
+ using __iter = _If<__is_const (__libcpp_remove_reference_t <_Self>), const_iterator, iterator>;
670
+ auto __it = ranges::lower_bound (__self.__keys_ , __key, __self.__compare_ );
671
+ auto __last = __self.__keys_ .end ();
666
672
if (__it == __last || __self.__compare_ (__key, *__it)) {
667
- return std::make_pair (__it, __it);
673
+ return std::make_pair (__iter ( __it), __iter ( __it) );
668
674
}
669
- return std::make_pair (__it, std::next (__it));
675
+ return std::make_pair (__iter ( __it), __iter ( std::next (__it) ));
670
676
}
671
677
672
678
template <class _KeyArg >
@@ -676,18 +682,18 @@ class flat_set {
676
682
clear () /* noexcept */ ;
677
683
}
678
684
});
679
- auto __key_it = __keys_.emplace (__it, std::forward<_KeyArg>(__key));
685
+ auto __key_it = __keys_.emplace (__it. __base () , std::forward<_KeyArg>(__key));
680
686
__on_failure.__complete ();
681
- return __key_it;
687
+ return iterator ( std::move ( __key_it)) ;
682
688
}
683
689
684
690
template <class _Kp >
685
691
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool > __try_emplace (_Kp&& __key) {
686
692
auto __it = lower_bound (__key);
687
693
if (__it == end () || __compare_ (__key, *__it)) {
688
- return pair<iterator, bool >(__emplace_exact_pos (__it, std::forward<_Kp>(__key)), true );
694
+ return pair<iterator, bool >(iterator ( __emplace_exact_pos (__it, std::forward<_Kp>(__key) )), true );
689
695
} else {
690
- return pair<iterator, bool >(std::move (__it), false );
696
+ return pair<iterator, bool >(iterator ( std::move (__it) ), false );
691
697
}
692
698
}
693
699
0 commit comments