31 template <
typename Node,
typename Header,
typename Accessor >
35 enum class mark : std::uintptr_t
59 if ( item !=
nullptr ) {
60 auto raw =
reinterpret_cast< std::uintptr_t
>( item ) | 0x01;
61 ptr_ =
reinterpret_cast< void*
>( raw );
67 static_assert(
alignof( Node ) > 1 );
68 static_assert(
alignof( Header ) > 1 );
69 if ( ptr_ ==
nullptr )
76 template <
typename K >
79 return get_impl< K, K >( *
this );
82 template <
typename K >
83 [[nodiscard]]
const K*
get()
const
85 return get_impl< const K, K >( *
this );
90 return get_impl< Node, Node >( *
this );
95 return get_impl< const Node, Node >( *
this );
100 return find_header_impl< Header >( *
this );
105 return find_header_impl< const Header >( *
this );
110 match_impl( *
this, tf, uf );
113 void match(
auto&& tf,
auto&& uf )
const
115 match_impl( *
this, tf, uf );
120 return ptr_ ==
nullptr;
127 template <
typename RetType,
typename K >
128 static RetType* get_impl(
auto&
self )
130 static_assert( std::same_as< K, Header > || std::same_as< K, Node > );
132 if constexpr ( std::same_as< K, Header > ) {
134 return reinterpret_cast< RetType*
>(
self.pure_ptr() );
137 return reinterpret_cast< RetType*
>(
self.pure_ptr() );
142 static void match_impl(
auto&
self,
auto&& tf,
auto&& uf )
144 if (
auto* ptr =
self.
template get< Header >() )
146 else if (
auto* ptr =
self.
get_node() )
150 template <
typename RetType >
151 static RetType* find_header_impl(
auto&
self )
153 if (
auto* ptr =
self.
template get< Header >() )
155 else if (
auto* ptr =
self.
get_node() )
156 return &Accessor::get( *ptr );
160 [[nodiscard]] uint8_t ctlbit()
const
162 return reinterpret_cast< std::uintptr_t
>( ptr_ ) & 0x01;
165 static constexpr std::uintptr_t mask = ~static_cast< std::uintptr_t >( 0x01 );
167 [[nodiscard]]
void* pure_ptr()
const
169 auto raw =
reinterpret_cast< std::uintptr_t
>( ptr_ );
171 return reinterpret_cast< void*
>( raw );
174 void* ptr_ =
nullptr;
Definition: list_ptr.hpp:33
mark type() const
Definition: list_ptr.hpp:65
void match(auto &&tf, auto &&uf) const
Definition: list_ptr.hpp:113
K * get()
Definition: list_ptr.hpp:77
mark
Definition: list_ptr.hpp:36
const Header * find_header() const
Definition: list_ptr.hpp:103
Node * get_node()
Definition: list_ptr.hpp:88
list_ptr(Node *item) noexcept
Definition: list_ptr.hpp:52
auto operator<=>(const list_ptr &other) const =default
list_ptr() noexcept=default
Accessor accessor_type
Definition: list_ptr.hpp:44
Header header_type
Definition: list_ptr.hpp:43
bool operator==(std::nullptr_t) const
Definition: list_ptr.hpp:118
const K * get() const
Definition: list_ptr.hpp:83
bool operator==(const list_ptr &other) const =default
const Node * get_node() const
Definition: list_ptr.hpp:93
list_ptr(Header *item) noexcept
Definition: list_ptr.hpp:57
Header * find_header()
Definition: list_ptr.hpp:98
Node node_type
Definition: list_ptr.hpp:42
void match(auto &&tf, auto &&uf)
Definition: list_ptr.hpp:108
MIT License.
Definition: dag.hpp:27