CPP-TOOLBOX
Loading...
Searching...
No Matches
ExpiringTemporalVector< T > Class Template Reference

A vector-like container where elements expire after a certain time limit and can be retrieved by time. More...

#include <expiring_temporal_vector.hpp>

Public Types

using Clock = std::chrono::steady_clock
 
using TimePoint = Clock::time_point
 

Public Member Functions

 ExpiringTemporalVector (int time_limit_seconds)
 Constructor to initialize the expiring temporal vector with a time limit.
 
void push_back (const T &element)
 Add an element to the vector with the current timestamp.
 
std::vector< Tget_elements ()
 Get all elements currently in the vector.
 
std::vector< Tget_elements_since (TimePoint time)
 Get all elements with timestamps greater than or equal to the specified time.
 
std::vector< T >::iterator begin ()
 
std::vector< T >::iterator end ()
 

Detailed Description

template<typename T>
class ExpiringTemporalVector< T >

A vector-like container where elements expire after a certain time limit and can be retrieved by time.

Template Parameters
TThe type of elements stored in the container.

Member Typedef Documentation

◆ Clock

template<typename T>
using ExpiringTemporalVector< T >::Clock = std::chrono::steady_clock

◆ TimePoint

template<typename T>
using ExpiringTemporalVector< T >::TimePoint = Clock::time_point

Constructor & Destructor Documentation

◆ ExpiringTemporalVector()

template<typename T>
ExpiringTemporalVector< T >::ExpiringTemporalVector ( int time_limit_seconds)
explicit

Constructor to initialize the expiring temporal vector with a time limit.

Parameters
time_limitThe time duration after which elements expire.

Member Function Documentation

◆ begin()

template<typename T>
std::vector< T >::iterator ExpiringTemporalVector< T >::begin ( )

◆ end()

template<typename T>
std::vector< T >::iterator ExpiringTemporalVector< T >::end ( )

◆ get_elements()

template<typename T>
std::vector< T > ExpiringTemporalVector< T >::get_elements ( )

Get all elements currently in the vector.

Returns
A vector of elements, excluding those that are expired.

◆ get_elements_since()

template<typename T>
std::vector< T > ExpiringTemporalVector< T >::get_elements_since ( TimePoint time)

Get all elements with timestamps greater than or equal to the specified time.

Parameters
timeThe time point to compare against.
Returns
A vector of elements with timestamps greater than or equal to the input time.

◆ push_back()

template<typename T>
void ExpiringTemporalVector< T >::push_back ( const T & element)

Add an element to the vector with the current timestamp.

Parameters
elementThe element to be added.

The documentation for this class was generated from the following file: