65#include <initializer_list>
119 [[nodiscard]]
bool empty(
void )
const {
return( f_n == 0 ); }
122 [[nodiscard]] std::size_t
size(
void )
const {
return( f_n ); }
126 [[nodiscard]]
const T &
front(
void )
const;
130 [[nodiscard]]
const T &
back(
void )
const;
177 void reverse(
void ) { std::swap( f_head , f_tail ); }
187 template<
bool Const >
196 using reference = std::conditional_t< Const , const T & , T & >;
198 using pointer = std::conditional_t< Const , const T * , T * >;
204 Iterator( Cell * p , Cell * c ) : f_p( p ) , f_c( c ) { }
208 requires( Const && ! K )
217 Cell * n = other( f_c , f_p );
224 Cell * p = other( f_p , f_c );
243 return( ( f_c == o.f_c ) && ( f_p == o.f_p ) );
249 Cell * f_p =
nullptr;
250 Cell * f_c =
nullptr;
258 return(
iterator(
nullptr , f_head ) );
282 static std::uintptr_t word(
const Cell * a ) {
283 return(
reinterpret_cast< std::uintptr_t
>( a ) );
287 static Cell * other(
const Cell * c ,
const Cell * p ) {
288 return(
reinterpret_cast< Cell *
>( c->link ^ word( p ) ) );
292 [[nodiscard]]
bool walks(
void )
const;
294 Cell * f_head =
nullptr;
295 Cell * f_tail =
nullptr;
297 ObjectPool< Cell > f_pool;
316template< std::
unsigned_
integral U >
327#include "ADS/sequence/impl/XorList.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
A pool of objects of one type, beyond the book: make() builds an object in a slot of the pool and fre...
std::bidirectional_iterator_tag iterator_category
bidirectional
Definition XorList.h:192
std::ptrdiff_t difference_type
the distances
Definition XorList.h:194
Iterator operator++(int)
to the next item, returning the iterator before the step
Definition XorList.h:230
bool operator==(const Iterator &o) const
equal on the same cell
Definition XorList.h:242
Iterator operator--(int)
to the previous item, returning the iterator before the step
Definition XorList.h:236
Iterator & operator--(void)
to the previous cell
Definition XorList.h:223
reference operator*(void) const
the item
Definition XorList.h:212
pointer operator->(void) const
the address of the item
Definition XorList.h:214
std::conditional_t< Const, const T *, T * > pointer
a pointer to an item, constant if Const
Definition XorList.h:198
Iterator(Cell *p, Cell *c)
on the cell , coming from
Definition XorList.h:204
Iterator(const Iterator< K > &o)
the constant iterator from the mutable one
Definition XorList.h:209
Iterator & operator++(void)
to the next cell,
Definition XorList.h:216
Iterator(void)=default
an iterator on no list
T value_type
the items
Definition XorList.h:193
friend class Iterator
Definition XorList.h:248
std::conditional_t< Const, const T &, T & > reference
a reference to an item, constant if Const
Definition XorList.h:196
const T & back(void) const
the last item
Iterator< true > const_iterator
on the constant items
Definition XorList.h:254
void swap(XorList &o) noexcept
exchanges the cells with those of o
std::ptrdiff_t difference_type
the type of the distances
Definition XorList.h:93
iterator begin(void)
the iterator on the first item
Definition XorList.h:257
std::size_t size_type
the type of the sizes
Definition XorList.h:92
~XorList()
destroys the items
XorList(const XorList &o)
a copy of o, cell by cell
const_iterator end(void) const
the constant iterator past the last item
Definition XorList.h:267
const T & const_reference
a constant reference
Definition XorList.h:95
Iterator< false > iterator
the iterator on the items
Definition XorList.h:253
XorList & operator=(XorList o) noexcept
the items of o, by copy and swap
const_iterator begin(void) const
the constant iterator on the first item
Definition XorList.h:263
iterator end(void)
the iterator past the last item
Definition XorList.h:261
void push_front(const T &x)
at the front,
void clear(void)
removes all the items
std::size_t size(void) const
the number of items
Definition XorList.h:122
void reverse(void)
the order of the items reversed in , by exchanging the first and the last cell
Definition XorList.h:177
XorList(XorList &&o) noexcept
the cells of o, which is left empty
bool empty(void) const
true if there is no item
Definition XorList.h:119
void pop_back(void)
removes the last item, , the mirror of pop_front()
void push_back(const T &x)
at the back, , the mirror of push_front()
T value_type
the type of the items
Definition XorList.h:91
void pop_front(void)
removes the first item,
T & reference
a reference to an item
Definition XorList.h:94
const T & front(void) const
the first item
bool operator==(const XorList &o) const
the same items in the same order
XorList(std::initializer_list< T > l)
the items of l, in order
XorList(void)=default
the empty list
constexpr void xorSwap(U &a, U &b)
and swapped by three exclusive ors and no third variable (exercise 3.19 of Morin's book)