Skip to content
Snippets Groups Projects
Commit 67f93b95 authored by Florian Schmaus's avatar Florian Schmaus
Browse files

[LockedSet] Add insertAndGetSize()

parent 379ea507
No related branches found
No related tags found
No related merge requests found
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Fischer
// Copyright © 2020 Florian Fischer, 2021 Florian Schmaus
#pragma once
#include <iterator>
......@@ -10,11 +10,20 @@ namespace emper::lib::adt {
template <class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key>>
class LockedSet {
public:
using set_type = std::set<Key, Compare, Allocator>;
private:
std::mutex _mutex;
std::set<Key, Compare, Allocator> _set;
set_type _set;
public:
auto insertAndGetSize(const Key& item) -> typename set_type::size_type {
std::lock_guard<std::mutex> lock(_mutex);
_set.insert(item);
return _set.size();
}
auto insert(const Key& item)
-> std::pair<typename std::set<Key, Compare, Allocator>::iterator, bool> {
std::lock_guard<std::mutex> lock(_mutex);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment