Skip to content

Commit 2dc5b3b

Browse files
committed
Revert to libc++ pointer_traits::pointer_to with necessary cast
1 parent 41ead79 commit 2dc5b3b

File tree

1 file changed

+11
-59
lines changed

1 file changed

+11
-59
lines changed

libcxx/include/forward_list

Lines changed: 11 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,8 @@ struct __forward_node_traits {
300300
return __p;
301301
}
302302
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI static __begin_node_pointer __as_iter_node(__node_pointer __p) {
303-
# ifdef _LIBCPP_CXX03_LANG
304-
return static_cast<__begin_node_pointer>(__p);
305-
# else
306-
if constexpr (std::is_pointer<__begin_node_pointer>::value) {
307-
return static_cast<__begin_node_pointer>(__p);
308-
} else {
309-
return __p ? __begin_node_pointer::pointer_to(*static_cast<__begin_node*>(std::addressof(*__p)))
310-
: static_cast<__begin_node_pointer>(nullptr);
311-
}
312-
# endif
303+
return __p ? pointer_traits<__begin_node_pointer>::pointer_to(*static_cast<__begin_node*>(std::addressof(*__p)))
304+
: static_cast<__begin_node_pointer>(nullptr);
313305
}
314306
};
315307

@@ -324,16 +316,9 @@ struct __forward_begin_node {
324316
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit __forward_begin_node(pointer __n) : __next_(__n) {}
325317

326318
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __next_as_begin() const {
327-
# ifdef _LIBCPP_CXX03_LANG
328-
return static_cast<__begin_node_pointer>(__next_);
329-
# else
330-
if constexpr (std::is_pointer<__begin_node_pointer>::value) {
331-
return static_cast<__begin_node_pointer>(__next_);
332-
} else {
333-
return __next_ ? __begin_node_pointer::pointer_to(*static_cast<__forward_begin_node*>(std::addressof(*__next_)))
334-
: static_cast<__begin_node_pointer>(nullptr);
335-
}
336-
# endif
319+
return __next_ ? pointer_traits<__begin_node_pointer>::pointer_to(
320+
*static_cast<__forward_begin_node*>(std::addressof(*__next_)))
321+
: static_cast<__begin_node_pointer>(nullptr);
337322
}
338323
};
339324

@@ -389,17 +374,8 @@ class _LIBCPP_TEMPLATE_VIS __forward_list_iterator {
389374

390375
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __get_begin() const { return __ptr_; }
391376
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __node_pointer __get_unsafe_node_pointer() const {
392-
# ifdef _LIBCPP_CXX03_LANG
393-
return static_cast<__node_pointer>(__ptr_);
394-
# else
395-
if constexpr (std::is_pointer<__node_pointer>::value) {
396-
return static_cast<__node_pointer>(__ptr_);
397-
} else {
398-
return __ptr_ ? __node_pointer::pointer_to(
399-
*static_cast<__node_type*>(const_cast<__begin_node_type*>(std::addressof(*__ptr_))))
400-
: static_cast<__node_pointer>(nullptr);
401-
}
402-
# endif
377+
return __ptr_ ? pointer_traits<__node_pointer>::pointer_to(*static_cast<__node_type*>(std::addressof(*__ptr_)))
378+
: static_cast<__node_pointer>(nullptr);
403379
}
404380

405381
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_iterator(nullptr_t) _NOEXCEPT
@@ -469,17 +445,8 @@ class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator {
469445

470446
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __get_begin() const { return __ptr_; }
471447
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __node_pointer __get_unsafe_node_pointer() const {
472-
# ifdef _LIBCPP_CXX03_LANG
473-
return static_cast<__node_pointer>(__ptr_);
474-
# else
475-
if constexpr (std::is_pointer<__node_pointer>::value) {
476-
return static_cast<__node_pointer>(__ptr_);
477-
} else {
478-
return __ptr_ ? __node_pointer::pointer_to(
479-
*static_cast<__node_type*>(const_cast<__begin_node_type*>(std::addressof(*__ptr_))))
480-
: static_cast<__node_pointer>(nullptr);
481-
}
482-
# endif
448+
return __ptr_ ? pointer_traits<__node_pointer>::pointer_to(*static_cast<__node_type*>(std::addressof(*__ptr_)))
449+
: static_cast<__node_pointer>(nullptr);
483450
}
484451

485452
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit __forward_list_const_iterator(nullptr_t) _NOEXCEPT
@@ -553,27 +520,12 @@ protected:
553520
_LIBCPP_COMPRESSED_PAIR(__begin_node, __before_begin_, __node_allocator, __alloc_);
554521

555522
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __before_begin() _NOEXCEPT {
556-
# ifdef _LIBCPP_CXX03_LANG
557523
return pointer_traits<__begin_node_pointer>::pointer_to(__before_begin_);
558-
# else
559-
if constexpr (std::is_pointer<__begin_node_pointer>::value) {
560-
return std::addressof(__before_begin_);
561-
} else {
562-
return __begin_node_pointer::pointer_to(*std::addressof(__before_begin_));
563-
}
564-
# endif
565524
}
566525

567526
_LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI __begin_node_pointer __before_begin() const _NOEXCEPT {
568-
# ifdef _LIBCPP_CXX03_LANG
569-
return pointer_traits<__begin_node_pointer>::pointer_to(const_cast<__begin_node&>(__before_begin_));
570-
# else
571-
if constexpr (std::is_pointer<__begin_node_pointer>::value) {
572-
return const_cast<__begin_node*>(std::addressof(__before_begin_));
573-
} else {
574-
return __begin_node_pointer::pointer_to(*const_cast<__begin_node*>(std::addressof(__before_begin_)));
575-
}
576-
# endif
527+
return pointer_traits<__begin_node_pointer>::pointer_to(
528+
*const_cast<__begin_node*>(std::addressof(__before_begin_)));
577529
}
578530

579531
typedef __forward_list_iterator<__node_pointer> iterator;

0 commit comments

Comments
 (0)