Skip to content

Commit 73cd84a

Browse files
authored
[NFC][libc++] Adds (multi|)(map|set) forward declarations. (#131541)
This removes duplicated forward declarations of these classes. closes: #131518
1 parent 99b1a2a commit 73cd84a

File tree

9 files changed

+85
-25
lines changed

9 files changed

+85
-25
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,14 @@ set(files
439439
__fwd/get.h
440440
__fwd/ios.h
441441
__fwd/istream.h
442+
__fwd/map.h
442443
__fwd/mdspan.h
443444
__fwd/memory.h
444445
__fwd/memory_resource.h
445446
__fwd/ostream.h
446447
__fwd/pair.h
447448
__fwd/queue.h
449+
__fwd/set.h
448450
__fwd/span.h
449451
__fwd/sstream.h
450452
__fwd/stack.h

libcxx/include/__functional/operations.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <__config>
1414
#include <__functional/binary_function.h>
1515
#include <__functional/unary_function.h>
16+
#include <__fwd/functional.h>
1617
#include <__type_traits/desugars_to.h>
1718
#include <__type_traits/is_integral.h>
1819
#include <__utility/forward.h>
@@ -349,11 +350,7 @@ struct _LIBCPP_TEMPLATE_VIS not_equal_to<void> {
349350
};
350351
#endif
351352

352-
#if _LIBCPP_STD_VER >= 14
353-
template <class _Tp = void>
354-
#else
355353
template <class _Tp>
356-
#endif
357354
struct _LIBCPP_TEMPLATE_VIS less : __binary_function<_Tp, _Tp, bool> {
358355
typedef bool __result_type; // used by valarray
359356
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {

libcxx/include/__fwd/functional.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717

1818
_LIBCPP_BEGIN_NAMESPACE_STD
1919

20+
#if _LIBCPP_STD_VER >= 14
21+
template <class _Tp = void>
22+
#else
23+
template <class _Tp>
24+
#endif
25+
struct _LIBCPP_TEMPLATE_VIS less;
26+
2027
template <class>
2128
struct _LIBCPP_TEMPLATE_VIS hash;
2229

libcxx/include/__fwd/map.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___FWD_MAP_H
10+
#define _LIBCPP___FWD_MAP_H
11+
12+
#include <__config>
13+
#include <__fwd/functional.h>
14+
#include <__fwd/memory.h>
15+
#include <__fwd/pair.h>
16+
17+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18+
# pragma GCC system_header
19+
#endif
20+
21+
_LIBCPP_BEGIN_NAMESPACE_STD
22+
23+
template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
24+
class _LIBCPP_TEMPLATE_VIS map;
25+
26+
template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
27+
class _LIBCPP_TEMPLATE_VIS multimap;
28+
29+
_LIBCPP_END_NAMESPACE_STD
30+
31+
#endif // _LIBCPP___FWD_MAP_H

libcxx/include/__fwd/set.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___FWD_SET_H
10+
#define _LIBCPP___FWD_SET_H
11+
12+
#include <__config>
13+
#include <__fwd/functional.h>
14+
#include <__fwd/memory.h>
15+
16+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17+
# pragma GCC system_header
18+
#endif
19+
20+
_LIBCPP_BEGIN_NAMESPACE_STD
21+
22+
template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
23+
class _LIBCPP_TEMPLATE_VIS set;
24+
25+
template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
26+
class _LIBCPP_TEMPLATE_VIS multiset;
27+
28+
_LIBCPP_END_NAMESPACE_STD
29+
30+
#endif // _LIBCPP___FWD_SET_H

libcxx/include/__tree

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <__algorithm/min.h>
1414
#include <__assert>
1515
#include <__config>
16+
#include <__fwd/map.h>
17+
#include <__fwd/set.h>
1618
#include <__iterator/distance.h>
1719
#include <__iterator/iterator_traits.h>
1820
#include <__iterator/next.h>
@@ -48,15 +50,6 @@ _LIBCPP_PUSH_MACROS
4850

4951
_LIBCPP_BEGIN_NAMESPACE_STD
5052

51-
template <class, class, class, class>
52-
class _LIBCPP_TEMPLATE_VIS map;
53-
template <class, class, class, class>
54-
class _LIBCPP_TEMPLATE_VIS multimap;
55-
template <class, class, class>
56-
class _LIBCPP_TEMPLATE_VIS set;
57-
template <class, class, class>
58-
class _LIBCPP_TEMPLATE_VIS multiset;
59-
6053
template <class _Tp, class _Compare, class _Allocator>
6154
class __tree;
6255
template <class _Tp, class _NodePtr, class _DiffType>

libcxx/include/map

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ 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>
585586
# include <__iterator/erase_if_container.h>
586587
# include <__iterator/iterator_traits.h>
587588
# include <__iterator/ranges_iterator_traits.h>
@@ -756,10 +757,6 @@ public:
756757
}
757758
};
758759

759-
template <class _Key, class _Tp, class _Compare, class _Allocator>
760-
class map;
761-
template <class _Key, class _Tp, class _Compare, class _Allocator>
762-
class multimap;
763760
template <class _TreeIterator>
764761
class __map_const_iterator;
765762

@@ -971,7 +968,7 @@ public:
971968
friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
972969
};
973970

974-
template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
971+
template <class _Key, class _Tp, class _Compare, class _Allocator>
975972
class _LIBCPP_TEMPLATE_VIS map {
976973
public:
977974
// types:
@@ -1656,7 +1653,7 @@ struct __container_traits<map<_Key, _Tp, _Compare, _Allocator> > {
16561653
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
16571654
};
16581655

1659-
template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
1656+
template <class _Key, class _Tp, class _Compare, class _Allocator>
16601657
class _LIBCPP_TEMPLATE_VIS multimap {
16611658
public:
16621659
// types:

libcxx/include/module.modulemap

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,10 @@ module std [system] {
13921392
header "__functional/not_fn.h"
13931393
export std.functional.perfect_forward // inherited from and using its operators
13941394
}
1395-
module operations { header "__functional/operations.h" }
1395+
module operations {
1396+
header "__functional/operations.h"
1397+
export std_core.fwd.functional
1398+
}
13961399
module perfect_forward {
13971400
header "__functional/perfect_forward.h"
13981401
export std.tuple
@@ -1558,6 +1561,7 @@ module std [system] {
15581561
}
15591562

15601563
module map {
1564+
module fwd { header "__fwd/map.h" }
15611565
header "map"
15621566
export *
15631567
}
@@ -1915,6 +1919,7 @@ module std [system] {
19151919
}
19161920

19171921
module set {
1922+
module fwd { header "__fwd/set.h" }
19181923
header "set"
19191924
export *
19201925
}
@@ -1982,7 +1987,7 @@ module std [system] {
19821987
export std.utility.element_count // used as part of the constexpr C function's API
19831988
}
19841989
module extern_template_lists { header "__string/extern_template_lists.h" }
1985-
module fwd { header "__fwd/string.h" }
1990+
module fwd { header "__fwd/string.h" }
19861991

19871992
header "string"
19881993
export *

libcxx/include/set

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ 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>
525526
# include <__iterator/erase_if_container.h>
526527
# include <__iterator/iterator_traits.h>
527528
# include <__iterator/ranges_iterator_traits.h>
@@ -570,9 +571,6 @@ _LIBCPP_PUSH_MACROS
570571
_LIBCPP_BEGIN_NAMESPACE_STD
571572

572573
template <class _Key, class _Compare, class _Allocator>
573-
class multiset;
574-
575-
template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
576574
class _LIBCPP_TEMPLATE_VIS set {
577575
public:
578576
// types:
@@ -1034,7 +1032,7 @@ struct __container_traits<set<_Key, _Compare, _Allocator> > {
10341032
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
10351033
};
10361034

1037-
template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
1035+
template <class _Key, class _Compare, class _Allocator>
10381036
class _LIBCPP_TEMPLATE_VIS multiset {
10391037
public:
10401038
// types:

0 commit comments

Comments
 (0)