30 template <
typename Node,
typename Header,
typename Accessor >
34 enum class mark : std::uintptr_t
58 if ( item !=
nullptr ) {
59 auto raw =
reinterpret_cast< std::uintptr_t
>( item ) | 0x01;
60 ptr_ =
reinterpret_cast< void*
>( raw );
66 static_assert(
alignof( Node ) > 1 );
67 static_assert(
alignof( Header ) > 1 );
68 if ( ptr_ ==
nullptr )
75 template <
typename K >
78 return get_impl< K, K >( *
this );
81 template <
typename K >
82 [[nodiscard]]
const K*
get()
const
84 return get_impl< const K, K >( *
this );
89 return get_impl< Node, Node >( *
this );
94 return get_impl< const Node, Node >( *
this );
99 return find_header_impl< Header >( *
this );
104 return find_header_impl< const Header >( *
this );
109 match_impl( *
this, tf, uf );
112 void match(
auto&& tf,
auto&& uf )
const
114 match_impl( *
this, tf, uf );
119 return ptr_ ==
nullptr;
126 template <
typename RetType,
typename K >
127 static RetType* get_impl(
auto&
self )
129 static_assert( std::same_as< K, Header > || std::same_as< K, Node > );
131 if constexpr ( std::same_as< K, Header > ) {
133 return reinterpret_cast< RetType*
>(
self.pure_ptr() );
136 return reinterpret_cast< RetType*
>(
self.pure_ptr() );
141 static void match_impl(
auto&
self,
auto&& tf,
auto&& uf )
143 if (
auto* ptr =
self.
template get< Header >() )
145 else if (
auto* ptr =
self.
get_node() )
149 template <
typename RetType >
150 static RetType* find_header_impl(
auto&
self )
152 if (
auto* ptr =
self.
template get< Header >() )
154 else if (
auto* ptr =
self.
get_node() )
155 return &Accessor::get( *ptr );
159 [[nodiscard]] uint8_t ctlbit()
const
161 return reinterpret_cast< std::uintptr_t
>( ptr_ ) & 0x01;
164 static constexpr std::uintptr_t mask = ~static_cast< std::uintptr_t >( 0x01 );
166 [[nodiscard]]
void* pure_ptr()
const
168 auto raw =
reinterpret_cast< std::uintptr_t
>( ptr_ );
170 return reinterpret_cast< void*
>( raw );
173 void* ptr_ =
nullptr;
Definition: list_ptr.hpp:32
mark type() const
Definition: list_ptr.hpp:64
void match(auto &&tf, auto &&uf) const
Definition: list_ptr.hpp:112
K * get()
Definition: list_ptr.hpp:76
mark
Definition: list_ptr.hpp:35
const Header * find_header() const
Definition: list_ptr.hpp:102
Node * get_node()
Definition: list_ptr.hpp:87
list_ptr(Node *item) noexcept
Definition: list_ptr.hpp:51
auto operator<=>(const list_ptr &other) const =default
list_ptr() noexcept=default
Accessor accessor_type
Definition: list_ptr.hpp:43
Header header_type
Definition: list_ptr.hpp:42
bool operator==(std::nullptr_t) const
Definition: list_ptr.hpp:117
const K * get() const
Definition: list_ptr.hpp:82
bool operator==(const list_ptr &other) const =default
const Node * get_node() const
Definition: list_ptr.hpp:92
list_ptr(Header *item) noexcept
Definition: list_ptr.hpp:56
Header * find_header()
Definition: list_ptr.hpp:97
Node node_type
Definition: list_ptr.hpp:41
void match(auto &&tf, auto &&uf)
Definition: list_ptr.hpp:107
MIT License.
Definition: dag.hpp:27