mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-03 08:46:46 +00:00
27 lines
660 B
C++
27 lines
660 B
C++
#pragma once
|
|
|
|
#include <xrpl/beast/container/aged_container.h>
|
|
|
|
#include <chrono>
|
|
#include <type_traits>
|
|
|
|
namespace beast {
|
|
|
|
/** Expire aged container items past the specified age. */
|
|
template <class AgedContainer, class Rep, class Period>
|
|
std::enable_if_t<IsAgedContainer<AgedContainer>::value, std::size_t>
|
|
expire(AgedContainer& c, std::chrono::duration<Rep, Period> const& age)
|
|
{
|
|
std::size_t n(0);
|
|
auto const expired(c.clock().now() - age);
|
|
for (auto iter(c.chronological.cbegin());
|
|
iter != c.chronological.cend() && iter.when() <= expired;)
|
|
{
|
|
iter = c.erase(iter);
|
|
++n;
|
|
}
|
|
return n;
|
|
}
|
|
|
|
} // namespace beast
|