Skip to content

Commit 6897ca4

Browse files
authored
[libc++] Remove unnecessary friend declarations from <__tree> (#152133)
Removing the unnecessary friend declarations from `<__tree>` also removes the need for forward declaration headers for `map` and `set`, which this patch also removes.
1 parent 6abf4f3 commit 6897ca4

File tree

7 files changed

+14
-100
lines changed

7 files changed

+14
-100
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,14 +447,12 @@ set(files
447447
__fwd/get.h
448448
__fwd/ios.h
449449
__fwd/istream.h
450-
__fwd/map.h
451450
__fwd/mdspan.h
452451
__fwd/memory.h
453452
__fwd/memory_resource.h
454453
__fwd/ostream.h
455454
__fwd/pair.h
456455
__fwd/queue.h
457-
__fwd/set.h
458456
__fwd/span.h
459457
__fwd/sstream.h
460458
__fwd/stack.h

libcxx/include/__fwd/map.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

libcxx/include/__fwd/set.h

Lines changed: 0 additions & 30 deletions
This file was deleted.

libcxx/include/__tree

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
#include <__algorithm/min.h>
1414
#include <__assert>
1515
#include <__config>
16-
#include <__fwd/map.h>
1716
#include <__fwd/pair.h>
18-
#include <__fwd/set.h>
1917
#include <__iterator/distance.h>
2018
#include <__iterator/iterator_traits.h>
2119
#include <__iterator/next.h>
@@ -686,16 +684,6 @@ private:
686684
friend class __tree;
687685
template <class, class, class>
688686
friend class __tree_const_iterator;
689-
template <class>
690-
friend class __map_iterator;
691-
template <class, class, class, class>
692-
friend class map;
693-
template <class, class, class, class>
694-
friend class multimap;
695-
template <class, class, class>
696-
friend class set;
697-
template <class, class, class>
698-
friend class multiset;
699687
};
700688

701689
template <class _Tp, class _NodePtr, class _DiffType>
@@ -709,18 +697,15 @@ class __tree_const_iterator {
709697
__end_node_pointer __ptr_;
710698

711699
public:
712-
using iterator_category = bidirectional_iterator_tag;
713-
using value_type = __get_node_value_type_t<_Tp>;
714-
using difference_type = _DiffType;
715-
using reference = const value_type&;
716-
using pointer = __rebind_pointer_t<_NodePtr, const value_type>;
700+
using iterator_category = bidirectional_iterator_tag;
701+
using value_type = __get_node_value_type_t<_Tp>;
702+
using difference_type = _DiffType;
703+
using reference = const value_type&;
704+
using pointer = __rebind_pointer_t<_NodePtr, const value_type>;
705+
using __non_const_iterator _LIBCPP_NODEBUG = __tree_iterator<_Tp, __node_pointer, difference_type>;
717706

718707
_LIBCPP_HIDE_FROM_ABI __tree_const_iterator() _NOEXCEPT : __ptr_(nullptr) {}
719708

720-
private:
721-
typedef __tree_iterator<_Tp, __node_pointer, difference_type> __non_const_iterator;
722-
723-
public:
724709
_LIBCPP_HIDE_FROM_ABI __tree_const_iterator(__non_const_iterator __p) _NOEXCEPT : __ptr_(__p.__ptr_) {}
725710

726711
_LIBCPP_HIDE_FROM_ABI reference operator*() const { return __get_np()->__value_; }
@@ -762,16 +747,6 @@ private:
762747

763748
template <class, class, class>
764749
friend class __tree;
765-
template <class, class, class, class>
766-
friend class map;
767-
template <class, class, class, class>
768-
friend class multimap;
769-
template <class, class, class>
770-
friend class set;
771-
template <class, class, class>
772-
friend class multiset;
773-
template <class>
774-
friend class __map_const_iterator;
775750
};
776751

777752
template <class _Tp, class _Compare>

libcxx/include/map

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@ erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
582582
# include <__functional/binary_function.h>
583583
# include <__functional/is_transparent.h>
584584
# include <__functional/operations.h>
585-
# include <__fwd/map.h>
586585
# include <__iterator/erase_if_container.h>
587586
# include <__iterator/iterator_traits.h>
588587
# include <__iterator/ranges_iterator_traits.h>
@@ -861,7 +860,10 @@ public:
861860
friend class __tree_const_iterator;
862861
};
863862

864-
template <class _Key, class _Tp, class _Compare, class _Allocator>
863+
template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
864+
class multimap;
865+
866+
template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
865867
class map {
866868
public:
867869
// types:

libcxx/include/module.modulemap.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,6 @@ module std [system] {
16071607
}
16081608

16091609
module map {
1610-
module fwd { header "__fwd/map.h" }
16111610
header "map"
16121611
export *
16131612
export std.iterator.reverse_iterator
@@ -1974,7 +1973,6 @@ module std [system] {
19741973
}
19751974

19761975
module set {
1977-
module fwd { header "__fwd/set.h" }
19781976
header "set"
19791977
export *
19801978
export std.iterator.reverse_iterator

libcxx/include/set

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,6 @@ erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
522522
# include <__config>
523523
# include <__functional/is_transparent.h>
524524
# include <__functional/operations.h>
525-
# include <__fwd/set.h>
526525
# include <__iterator/erase_if_container.h>
527526
# include <__iterator/iterator_traits.h>
528527
# include <__iterator/ranges_iterator_traits.h>
@@ -570,7 +569,10 @@ _LIBCPP_PUSH_MACROS
570569

571570
_LIBCPP_BEGIN_NAMESPACE_STD
572571

573-
template <class _Key, class _Compare, class _Allocator>
572+
template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
573+
class multiset;
574+
575+
template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
574576
class set {
575577
public:
576578
// types:

0 commit comments

Comments
 (0)