Cbeam
Loading...
Searching...
No Matches
cbeam::container::thread_safe_set< T > Class Template Reference

Thread-safe wrapper for std::set. More...

#include <thread_safe_set.hpp>

Inheritance diagram for cbeam::container::thread_safe_set< T >:
Collaboration diagram for cbeam::container::thread_safe_set< T >:

Public Member Functions

template<typename... Args>
std::pair< typename std::set< T >::iterator, bool > emplace (Args &&... args)
 Constructs an element in-place within the underlying std::set.
 
bool insert (const T &value)
 Inserts a copy of value into the underlying std::set.
 
bool erase (const T &value)
 Erases a value from the set if it exists.
 
bool contains (const T &value) const
 Checks whether the specified value is contained in the set.
 
- Public Member Functions inherited from cbeam::container::thread_safe_container< std::set< T > >
lock_guard get_lock_guard () const
 Acquires a lock guard for the set, ensuring thread safety.
 
 thread_safe_container ()=default
 Default constructor.
 
virtual ~thread_safe_container () noexcept
 
bool empty () const
 Checks if the container is empty.
 
void clear ()
 Clears the contents.
 
std::size_t size () const
 Returns the number of elements.
 
auto begin ()
 Returns an iterator to the beginning.
 
auto end ()
 Returns an iterator to the end.
 
bool is_being_modified () const
 

Additional Inherited Members

- Protected Attributes inherited from cbeam::container::thread_safe_container< std::set< T > >
std::recursive_mutex _mutex
 Mutex to protect access to _container.
 
_container
 Internal non-thread safe container.
 
std::atomic< bool > _is_being_modified
 

Detailed Description

template<typename T>
class cbeam::container::thread_safe_set< T >

Thread-safe wrapper for std::set.

Template Parameters
TType of the elements

Member Function Documentation

◆ contains()

template<typename T>
bool cbeam::container::thread_safe_set< T >::contains ( const T & value) const
inline

Checks whether the specified value is contained in the set.

This function acquires a lock to ensure thread safety while searching.

Parameters
valueThe value to look for.
Returns
true if the set contains the value, false otherwise.

◆ emplace()

template<typename T>
template<typename... Args>
std::pair< typename std::set< T >::iterator, bool > cbeam::container::thread_safe_set< T >::emplace ( Args &&... args)
inline

Constructs an element in-place within the underlying std::set.

This function uses perfect forwarding to create an element of type T directly within the set. It throws a runtime_error if the set is currently being modified.

Template Parameters
ArgsThe parameter pack for constructing the T object.
Parameters
argsArguments to forward to the constructor of T.
Returns
A std::pair containing an iterator to the inserted element and a boolean indicating success/failure.

◆ erase()

template<typename T>
bool cbeam::container::thread_safe_set< T >::erase ( const T & value)
inline

Erases a value from the set if it exists.

If the set is currently being modified, a runtime_error is thrown.

Parameters
valueThe value to erase.
Returns
true if the value was present and erased, false otherwise.

◆ insert()

template<typename T>
bool cbeam::container::thread_safe_set< T >::insert ( const T & value)
inline

Inserts a copy of value into the underlying std::set.

If the set is currently being modified, a runtime_error is thrown.

Parameters
valueThe value to insert into the set.
Returns
true if the insertion was successful, false if the value already exists.

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