[libcxx-commits] [libcxx] [libc++][NFC] Move some really simple function defintions into the body of __tree (PR #157424)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Sep 8 03:57:39 PDT 2025
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/157424
None
>From 797a2ab6be60b8972a8b067247674148892f37d1 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Mon, 8 Sep 2025 12:57:21 +0200
Subject: [PATCH] [libc++][NFC] Move some really simple function defintions
into the body of __tree
---
libcxx/include/__tree | 71 +++++++++++++++----------------------------
1 file changed, 25 insertions(+), 46 deletions(-)
diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index 8b4bda8c7a3ee..81a73342cc61b 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -862,9 +862,21 @@ public:
using const_iterator = __tree_const_iterator<_Tp, __node_pointer, difference_type>;
_LIBCPP_HIDE_FROM_ABI explicit __tree(const value_compare& __comp) _NOEXCEPT_(
- is_nothrow_default_constructible<__node_allocator>::value&& is_nothrow_copy_constructible<value_compare>::value);
- _LIBCPP_HIDE_FROM_ABI explicit __tree(const allocator_type& __a);
- _LIBCPP_HIDE_FROM_ABI __tree(const value_compare& __comp, const allocator_type& __a);
+ is_nothrow_default_constructible<__node_allocator>::value&& is_nothrow_copy_constructible<value_compare>::value)
+ : __size_(0), __value_comp_(__comp) {
+ __begin_node_ = __end_node();
+ }
+
+ _LIBCPP_HIDE_FROM_ABI explicit __tree(const allocator_type& __a)
+ : __begin_node_(), __node_alloc_(__node_allocator(__a)), __size_(0) {
+ __begin_node_ = __end_node();
+ }
+
+ _LIBCPP_HIDE_FROM_ABI __tree(const value_compare& __comp, const allocator_type& __a)
+ : __begin_node_(), __node_alloc_(__node_allocator(__a)), __size_(0), __value_comp_(__comp) {
+ __begin_node_ = __end_node();
+ }
+
_LIBCPP_HIDE_FROM_ABI __tree(const __tree& __t);
_LIBCPP_HIDE_FROM_ABI __tree& operator=(const __tree& __t);
template <class _ForwardIterator>
@@ -874,13 +886,20 @@ public:
_LIBCPP_HIDE_FROM_ABI __tree(__tree&& __t) _NOEXCEPT_(
is_nothrow_move_constructible<__node_allocator>::value&& is_nothrow_move_constructible<value_compare>::value);
_LIBCPP_HIDE_FROM_ABI __tree(__tree&& __t, const allocator_type& __a);
+
_LIBCPP_HIDE_FROM_ABI __tree& operator=(__tree&& __t)
_NOEXCEPT_(is_nothrow_move_assignable<value_compare>::value &&
((__node_traits::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<__node_allocator>::value) ||
- allocator_traits<__node_allocator>::is_always_equal::value));
+ allocator_traits<__node_allocator>::is_always_equal::value)) {
+ __move_assign(__t, integral_constant<bool, __node_traits::propagate_on_container_move_assignment::value>());
+ return *this;
+ }
- _LIBCPP_HIDE_FROM_ABI ~__tree();
+ _LIBCPP_HIDE_FROM_ABI ~__tree() {
+ static_assert(is_copy_constructible<value_compare>::value, "Comparator must be copy-constructible.");
+ destroy(__root());
+ }
_LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return iterator(__begin_node_); }
_LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return const_iterator(__begin_node_); }
@@ -1204,7 +1223,7 @@ private:
_LIBCPP_HIDE_FROM_ABI __node_holder __construct_node(_Args&&... __args);
// TODO: Make this _LIBCPP_HIDE_FROM_ABI
- _LIBCPP_HIDDEN void destroy(__node_pointer __nd) _NOEXCEPT;
+ _LIBCPP_HIDDEN void destroy(__node_pointer __nd) _NOEXCEPT { (__tree_deleter(__node_alloc_))(__nd); }
_LIBCPP_HIDE_FROM_ABI void __move_assign(__tree& __t, false_type);
_LIBCPP_HIDE_FROM_ABI void __move_assign(__tree& __t, true_type) _NOEXCEPT_(
@@ -1373,25 +1392,6 @@ private:
}
};
-template <class _Tp, class _Compare, class _Allocator>
-__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp) _NOEXCEPT_(
- is_nothrow_default_constructible<__node_allocator>::value&& is_nothrow_copy_constructible<value_compare>::value)
- : __size_(0), __value_comp_(__comp) {
- __begin_node_ = __end_node();
-}
-
-template <class _Tp, class _Compare, class _Allocator>
-__tree<_Tp, _Compare, _Allocator>::__tree(const allocator_type& __a)
- : __begin_node_(), __node_alloc_(__node_allocator(__a)), __size_(0) {
- __begin_node_ = __end_node();
-}
-
-template <class _Tp, class _Compare, class _Allocator>
-__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp, const allocator_type& __a)
- : __begin_node_(), __node_alloc_(__node_allocator(__a)), __size_(0), __value_comp_(__comp) {
- __begin_node_ = __end_node();
-}
-
// Precondition: __size_ != 0
template <class _Tp, class _Compare, class _Allocator>
typename __tree<_Tp, _Compare, _Allocator>::__node_pointer
@@ -1588,27 +1588,6 @@ void __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, false_type) {
}
}
-template <class _Tp, class _Compare, class _Allocator>
-__tree<_Tp, _Compare, _Allocator>& __tree<_Tp, _Compare, _Allocator>::operator=(__tree&& __t)
- _NOEXCEPT_(is_nothrow_move_assignable<value_compare>::value &&
- ((__node_traits::propagate_on_container_move_assignment::value &&
- is_nothrow_move_assignable<__node_allocator>::value) ||
- allocator_traits<__node_allocator>::is_always_equal::value)) {
- __move_assign(__t, integral_constant<bool, __node_traits::propagate_on_container_move_assignment::value>());
- return *this;
-}
-
-template <class _Tp, class _Compare, class _Allocator>
-__tree<_Tp, _Compare, _Allocator>::~__tree() {
- static_assert(is_copy_constructible<value_compare>::value, "Comparator must be copy-constructible.");
- destroy(__root());
-}
-
-template <class _Tp, class _Compare, class _Allocator>
-void __tree<_Tp, _Compare, _Allocator>::destroy(__node_pointer __nd) _NOEXCEPT {
- (__tree_deleter(__node_alloc_))(__nd);
-}
-
template <class _Tp, class _Compare, class _Allocator>
void __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t)
#if _LIBCPP_STD_VER <= 11
More information about the libcxx-commits
mailing list