loop: Add convenience functions and a foreach function without data
This commit adds convenience functions to the loop data type that
allow the caller to find the elements that come before or after an
element in a loop.
This further adds functions to shift the position of an element in
the loop to the back or the front, and a foreach function that
passes only the element pointer to the callback (this is useful for
calling things like free() from the foreach function).