mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-03 01:15:53 +00:00
Return popped element in List
This commit is contained in:
@@ -315,6 +315,14 @@ public:
|
|||||||
typedef Element* pointer;
|
typedef Element* pointer;
|
||||||
typedef Element const* const_pointer;
|
typedef Element const* const_pointer;
|
||||||
|
|
||||||
|
/** Thrown when some members are called with an empty list. */
|
||||||
|
struct empty_list_error : std::logic_error
|
||||||
|
{
|
||||||
|
empty_list_error () : std::logic_error ("empty list")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class Node : Uncopyable
|
class Node : Uncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -474,7 +482,7 @@ public:
|
|||||||
reference front ()
|
reference front ()
|
||||||
{
|
{
|
||||||
if (empty ())
|
if (empty ())
|
||||||
Throw (Error ().fail (__FILE__, __LINE__, Error::noMoreData));
|
Throw (empty_list_error (), __FILE__, __LINE__);
|
||||||
|
|
||||||
return element_from (m_head.m_next);
|
return element_from (m_head.m_next);
|
||||||
}
|
}
|
||||||
@@ -488,7 +496,7 @@ public:
|
|||||||
const_reference front () const
|
const_reference front () const
|
||||||
{
|
{
|
||||||
if (empty ())
|
if (empty ())
|
||||||
Throw (Error ().fail (__FILE__, __LINE__, Error::noMoreData));
|
Throw (empty_list_error (), __FILE__, __LINE__);
|
||||||
|
|
||||||
return element_from (m_head.m_next);
|
return element_from (m_head.m_next);
|
||||||
}
|
}
|
||||||
@@ -502,7 +510,7 @@ public:
|
|||||||
reference back ()
|
reference back ()
|
||||||
{
|
{
|
||||||
if (empty ())
|
if (empty ())
|
||||||
Throw (Error ().fail (__FILE__, __LINE__, Error::noMoreData));
|
Throw (empty_list_error (), __FILE__, __LINE__);
|
||||||
|
|
||||||
return element_from (m_tail.m_prev);
|
return element_from (m_tail.m_prev);
|
||||||
}
|
}
|
||||||
@@ -516,7 +524,7 @@ public:
|
|||||||
const_reference back () const
|
const_reference back () const
|
||||||
{
|
{
|
||||||
if (empty ())
|
if (empty ())
|
||||||
Throw (Error ().fail (__FILE__, __LINE__, Error::noMoreData));
|
Throw (empty_list_error (), __FILE__, __LINE__);
|
||||||
|
|
||||||
return element_from (m_tail.m_prev);
|
return element_from (m_tail.m_prev);
|
||||||
}
|
}
|
||||||
@@ -671,13 +679,13 @@ public:
|
|||||||
/** Remove the element at the beginning of the list.
|
/** Remove the element at the beginning of the list.
|
||||||
|
|
||||||
@invariant The list must not be empty.
|
@invariant The list must not be empty.
|
||||||
|
@return A reference to the popped element.
|
||||||
*/
|
*/
|
||||||
void pop_front ()
|
Element& pop_front ()
|
||||||
{
|
{
|
||||||
if (empty ())
|
Element& elem (front ());
|
||||||
Throw (Error ().fail (__FILE__, __LINE__, Error::noMoreData));
|
|
||||||
|
|
||||||
erase (begin ());
|
erase (begin ());
|
||||||
|
return elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Append an element at the end of the list.
|
/** Append an element at the end of the list.
|
||||||
@@ -694,13 +702,13 @@ public:
|
|||||||
/** Remove the element at the end of the list.
|
/** Remove the element at the end of the list.
|
||||||
|
|
||||||
@invariant The list must not be empty.
|
@invariant The list must not be empty.
|
||||||
|
@return A reference to the popped element.
|
||||||
*/
|
*/
|
||||||
void pop_back ()
|
Element& pop_back ()
|
||||||
{
|
{
|
||||||
if (empty ())
|
Element& elem (back ());
|
||||||
Throw (Error ().fail (__FILE__, __LINE__, Error::noMoreData));
|
|
||||||
|
|
||||||
erase (--end ());
|
erase (--end ());
|
||||||
|
return elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Swap contents with another list.
|
/** Swap contents with another list.
|
||||||
|
|||||||
Reference in New Issue
Block a user