Skip to content

[NFC][libc++] Adds (multi|)(map|set) forward declarations. #131541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,14 @@ set(files
__fwd/get.h
__fwd/ios.h
__fwd/istream.h
__fwd/map.h
__fwd/mdspan.h
__fwd/memory.h
__fwd/memory_resource.h
__fwd/ostream.h
__fwd/pair.h
__fwd/queue.h
__fwd/set.h
__fwd/span.h
__fwd/sstream.h
__fwd/stack.h
Expand Down
5 changes: 1 addition & 4 deletions libcxx/include/__functional/operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <__config>
#include <__functional/binary_function.h>
#include <__functional/unary_function.h>
#include <__fwd/functional.h>
#include <__type_traits/desugars_to.h>
#include <__type_traits/is_integral.h>
#include <__utility/forward.h>
Expand Down Expand Up @@ -349,11 +350,7 @@ struct _LIBCPP_TEMPLATE_VIS not_equal_to<void> {
};
#endif

#if _LIBCPP_STD_VER >= 14
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS less : __binary_function<_Tp, _Tp, bool> {
typedef bool __result_type; // used by valarray
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const {
Expand Down
7 changes: 7 additions & 0 deletions libcxx/include/__fwd/functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

_LIBCPP_BEGIN_NAMESPACE_STD

#if _LIBCPP_STD_VER >= 14
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS less;

template <class>
struct _LIBCPP_TEMPLATE_VIS hash;

Expand Down
31 changes: 31 additions & 0 deletions libcxx/include/__fwd/map.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___FWD_MAP_H
#define _LIBCPP___FWD_MAP_H

#include <__config>
#include <__fwd/functional.h>
#include <__fwd/memory.h>
#include <__fwd/pair.h>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
class _LIBCPP_TEMPLATE_VIS map;

template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
class _LIBCPP_TEMPLATE_VIS multimap;

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___FWD_MAP_H
30 changes: 30 additions & 0 deletions libcxx/include/__fwd/set.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___FWD_SET_H
#define _LIBCPP___FWD_SET_H

#include <__config>
#include <__fwd/functional.h>
#include <__fwd/memory.h>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
class _LIBCPP_TEMPLATE_VIS set;

template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
class _LIBCPP_TEMPLATE_VIS multiset;

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___FWD_SET_H
11 changes: 2 additions & 9 deletions libcxx/include/__tree
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <__algorithm/min.h>
#include <__assert>
#include <__config>
#include <__fwd/map.h>
#include <__fwd/set.h>
#include <__iterator/distance.h>
#include <__iterator/iterator_traits.h>
#include <__iterator/next.h>
Expand Down Expand Up @@ -48,15 +50,6 @@ _LIBCPP_PUSH_MACROS

_LIBCPP_BEGIN_NAMESPACE_STD

template <class, class, class, class>
class _LIBCPP_TEMPLATE_VIS map;
template <class, class, class, class>
class _LIBCPP_TEMPLATE_VIS multimap;
template <class, class, class>
class _LIBCPP_TEMPLATE_VIS set;
template <class, class, class>
class _LIBCPP_TEMPLATE_VIS multiset;

template <class _Tp, class _Compare, class _Allocator>
class __tree;
template <class _Tp, class _NodePtr, class _DiffType>
Expand Down
9 changes: 3 additions & 6 deletions libcxx/include/map
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
# include <__functional/binary_function.h>
# include <__functional/is_transparent.h>
# include <__functional/operations.h>
# include <__fwd/map.h>
# include <__iterator/erase_if_container.h>
# include <__iterator/iterator_traits.h>
# include <__iterator/ranges_iterator_traits.h>
Expand Down Expand Up @@ -756,10 +757,6 @@ public:
}
};

template <class _Key, class _Tp, class _Compare, class _Allocator>
class map;
template <class _Key, class _Tp, class _Compare, class _Allocator>
class multimap;
template <class _TreeIterator>
class __map_const_iterator;

Expand Down Expand Up @@ -971,7 +968,7 @@ public:
friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
};

template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
template <class _Key, class _Tp, class _Compare, class _Allocator>
class _LIBCPP_TEMPLATE_VIS map {
public:
// types:
Expand Down Expand Up @@ -1656,7 +1653,7 @@ struct __container_traits<map<_Key, _Tp, _Compare, _Allocator> > {
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
};

template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
template <class _Key, class _Tp, class _Compare, class _Allocator>
class _LIBCPP_TEMPLATE_VIS multimap {
public:
// types:
Expand Down
9 changes: 7 additions & 2 deletions libcxx/include/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,10 @@ module std [system] {
header "__functional/not_fn.h"
export std.functional.perfect_forward // inherited from and using its operators
}
module operations { header "__functional/operations.h" }
module operations {
header "__functional/operations.h"
export std_core.fwd.functional
}
module perfect_forward {
header "__functional/perfect_forward.h"
export std.tuple
Expand Down Expand Up @@ -1548,6 +1551,7 @@ module std [system] {
}

module map {
module fwd { header "__fwd/map.h" }
header "map"
export *
}
Expand Down Expand Up @@ -1905,6 +1909,7 @@ module std [system] {
}

module set {
module fwd { header "__fwd/set.h" }
header "set"
export *
}
Expand Down Expand Up @@ -1972,7 +1977,7 @@ module std [system] {
export std.utility.element_count // used as part of the constexpr C function's API
}
module extern_template_lists { header "__string/extern_template_lists.h" }
module fwd { header "__fwd/string.h" }
module fwd { header "__fwd/string.h" }

header "string"
export *
Expand Down
6 changes: 2 additions & 4 deletions libcxx/include/set
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
# include <__config>
# include <__functional/is_transparent.h>
# include <__functional/operations.h>
# include <__fwd/set.h>
# include <__iterator/erase_if_container.h>
# include <__iterator/iterator_traits.h>
# include <__iterator/ranges_iterator_traits.h>
Expand Down Expand Up @@ -570,9 +571,6 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD

template <class _Key, class _Compare, class _Allocator>
class multiset;

template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
class _LIBCPP_TEMPLATE_VIS set {
public:
// types:
Expand Down Expand Up @@ -1034,7 +1032,7 @@ struct __container_traits<set<_Key, _Compare, _Allocator> > {
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
};

template <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
template <class _Key, class _Compare, class _Allocator>
class _LIBCPP_TEMPLATE_VIS multiset {
public:
// types:
Expand Down