Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:14:03

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___STOP_TOKEN_INTRUSIVE_LIST_VIEW_H
0011 #define _LIBCPP___STOP_TOKEN_INTRUSIVE_LIST_VIEW_H
0012 
0013 #include <__assert>
0014 #include <__config>
0015 
0016 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0017 #  pragma GCC system_header
0018 #endif
0019 
0020 _LIBCPP_BEGIN_NAMESPACE_STD
0021 
0022 #if _LIBCPP_STD_VER >= 20
0023 
0024 template <class _Derived>
0025 struct __intrusive_node_base {
0026   _Derived* __next_ = nullptr;
0027   _Derived* __prev_ = nullptr;
0028 };
0029 
0030 // This class is a view of underlying double-linked list.
0031 // It does not own the nodes. It provides user-friendly
0032 // operations on the linked list.
0033 template <class _Node>
0034 struct __intrusive_list_view {
0035   _LIBCPP_HIDE_FROM_ABI __intrusive_list_view()                                        = default;
0036   _LIBCPP_HIDE_FROM_ABI __intrusive_list_view(__intrusive_list_view const&)            = default;
0037   _LIBCPP_HIDE_FROM_ABI __intrusive_list_view(__intrusive_list_view&&)                 = default;
0038   _LIBCPP_HIDE_FROM_ABI __intrusive_list_view& operator=(__intrusive_list_view const&) = default;
0039   _LIBCPP_HIDE_FROM_ABI __intrusive_list_view& operator=(__intrusive_list_view&&)      = default;
0040   _LIBCPP_HIDE_FROM_ABI ~__intrusive_list_view()                                       = default;
0041 
0042   _LIBCPP_HIDE_FROM_ABI bool __empty() const noexcept { return __head_ == nullptr; }
0043 
0044   _LIBCPP_HIDE_FROM_ABI void __push_front(_Node* __node) noexcept {
0045     __node->__next_ = __head_;
0046     if (__head_) {
0047       __head_->__prev_ = __node;
0048     }
0049     __head_ = __node;
0050   }
0051 
0052   _LIBCPP_HIDE_FROM_ABI _Node* __pop_front() noexcept {
0053     _Node* __front = __head_;
0054     __head_        = __head_->__next_;
0055     if (__head_) {
0056       __head_->__prev_ = nullptr;
0057     }
0058     // OK not to set __front->__next_ = nullptr as __front is not part of the list anymore
0059     return __front;
0060   }
0061 
0062   _LIBCPP_HIDE_FROM_ABI void __remove(_Node* __node) noexcept {
0063     if (__node->__prev_) {
0064       // prev exists, set its next to our next to skip __node
0065       __node->__prev_->__next_ = __node->__next_;
0066       if (__node->__next_) {
0067         __node->__next_->__prev_ = __node->__prev_;
0068       }
0069     } else {
0070       _LIBCPP_ASSERT_INTERNAL(__node == __head_, "Node to be removed has no prev node, so it has to be the head");
0071       __pop_front();
0072     }
0073   }
0074 
0075   _LIBCPP_HIDE_FROM_ABI bool __is_head(_Node* __node) noexcept { return __node == __head_; }
0076 
0077 private:
0078   _Node* __head_ = nullptr;
0079 };
0080 
0081 #endif // _LIBCPP_STD_VER >= 20
0082 
0083 _LIBCPP_END_NAMESPACE_STD
0084 
0085 #endif // _LIBCPP___STOP_TOKEN_INTRUSIVE_LIST_VIEW_H