mirror of https://github.com/infosecn1nja/C3.git
Workaround a scoped_lock CTAD problem
See: https://developercommunity.visualstudio.com/content/problem/842917/error-c3538-when-using-scoped-lock-in-derived-temp.htmldependabot/npm_and_yarn/Src/WebController/UI/websocket-extensions-0.1.4
parent
b0533d4668
commit
5a36970c3c
|
@ -10,7 +10,7 @@ namespace MWR
|
||||||
/// @param comparator function that returns true to keep iterate or false to stop.
|
/// @param comparator function that returns true to keep iterate or false to stop.
|
||||||
void For(std::function<bool(T const&)> comparator) const
|
void For(std::function<bool(T const&)> comparator) const
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(m_AccessMutex); // Request access to the underlying Container.
|
std::scoped_lock<std::mutex> lock(m_AccessMutex); // Request access to the underlying Container.
|
||||||
for (auto element : m_Container)
|
for (auto element : m_Container)
|
||||||
if (!comparator(element))
|
if (!comparator(element))
|
||||||
return;
|
return;
|
||||||
|
@ -21,7 +21,7 @@ namespace MWR
|
||||||
/// @return Element if existed, otherwise null.
|
/// @return Element if existed, otherwise null.
|
||||||
T Find(std::function<bool(T const&)> comparator) const
|
T Find(std::function<bool(T const&)> comparator) const
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(m_AccessMutex); // Request access to the underlying Container.
|
std::scoped_lock<std::mutex> lock(m_AccessMutex); // Request access to the underlying Container.
|
||||||
auto it = std::find_if(m_Container.begin(), m_Container.end(), comparator); // Find specified Element...
|
auto it = std::find_if(m_Container.begin(), m_Container.end(), comparator); // Find specified Element...
|
||||||
return it == std::end(m_Container) ? T{} : *it; // ...and return it (or null if it couldn't be found).
|
return it == std::end(m_Container) ? T{} : *it; // ...and return it (or null if it couldn't be found).
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ namespace MWR
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
T Add(Args&& ... args)
|
T Add(Args&& ... args)
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(m_AccessMutex); // Request access to the underlying Container.
|
std::scoped_lock<std::mutex> lock(m_AccessMutex); // Request access to the underlying Container.
|
||||||
m_Container.emplace_back(args...); // Add it at the end.
|
m_Container.emplace_back(args...); // Add it at the end.
|
||||||
return m_Container.back();
|
return m_Container.back();
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ namespace MWR
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
T TryAdd(std::function<bool(T const&)> comparator, Args&& ... args)
|
T TryAdd(std::function<bool(T const&)> comparator, Args&& ... args)
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(m_AccessMutex); // Request access to the underlying Container.
|
std::scoped_lock<std::mutex> lock(m_AccessMutex); // Request access to the underlying Container.
|
||||||
if (auto it = std::find_if(m_Container.begin(), m_Container.end(), comparator); it != m_Container.end()) // Find element...
|
if (auto it = std::find_if(m_Container.begin(), m_Container.end(), comparator); it != m_Container.end()) // Find element...
|
||||||
throw std::invalid_argument{ OBF("Tried to add an existing Element to the container.") }; // ...and throw.
|
throw std::invalid_argument{ OBF("Tried to add an existing Element to the container.") }; // ...and throw.
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ namespace MWR
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
T Ensure(std::function<bool(T const&)> comparator, Args&& ... args)
|
T Ensure(std::function<bool(T const&)> comparator, Args&& ... args)
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(m_AccessMutex); // Request access to the underlying Container.
|
std::scoped_lock<std::mutex> lock(m_AccessMutex); // Request access to the underlying Container.
|
||||||
if (auto it = std::find(m_Container.begin(), m_Container.end(), element); it != m_Container.end()) // Find element...
|
if (auto it = std::find(m_Container.begin(), m_Container.end(), element); it != m_Container.end()) // Find element...
|
||||||
return *it; // ...and return it.
|
return *it; // ...and return it.
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ namespace MWR
|
||||||
/// @throw std::invalid_argument on an attempt of removal of a non-existent Element.
|
/// @throw std::invalid_argument on an attempt of removal of a non-existent Element.
|
||||||
void Remove(T const& element)
|
void Remove(T const& element)
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(m_AccessMutex); // Request access to the underlying Container.
|
std::scoped_lock<std::mutex> lock(m_AccessMutex); // Request access to the underlying Container.
|
||||||
if (auto it = std::find(m_Container.begin(), m_Container.end(), element); it != m_Container.end()) // Find element...
|
if (auto it = std::find(m_Container.begin(), m_Container.end(), element); it != m_Container.end()) // Find element...
|
||||||
m_Container.erase(it); // ...and remove it.
|
m_Container.erase(it); // ...and remove it.
|
||||||
else
|
else
|
||||||
|
@ -88,7 +88,7 @@ namespace MWR
|
||||||
/// @throw std::invalid_argument on an attempt of removal of a non-existent Element.
|
/// @throw std::invalid_argument on an attempt of removal of a non-existent Element.
|
||||||
void Remove(std::function<bool(T const&)> comparator)
|
void Remove(std::function<bool(T const&)> comparator)
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(m_AccessMutex); // Request access to the underlying Container.
|
std::scoped_lock<std::mutex> lock(m_AccessMutex); // Request access to the underlying Container.
|
||||||
if (auto it = std::find_if(m_Container.begin(), m_Container.end(), comparator); it != m_Container.end()) // Find specified Element...
|
if (auto it = std::find_if(m_Container.begin(), m_Container.end(), comparator); it != m_Container.end()) // Find specified Element...
|
||||||
m_Container.erase(it); // ...and remove it.
|
m_Container.erase(it); // ...and remove it.
|
||||||
else
|
else
|
||||||
|
@ -101,7 +101,7 @@ namespace MWR
|
||||||
/// @throw std::invalid_argument on an attempt of removal of a non-existent Element.
|
/// @throw std::invalid_argument on an attempt of removal of a non-existent Element.
|
||||||
T Retrieve(std::function<bool(T const&)> comparator)
|
T Retrieve(std::function<bool(T const&)> comparator)
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(m_AccessMutex); // Request access to the underlying Container.
|
std::scoped_lock<std::mutex> lock(m_AccessMutex); // Request access to the underlying Container.
|
||||||
if (auto it = std::find_if(m_Container.begin(), m_Container.end(), comparator); it != m_Container.end()) // Find specified Element...
|
if (auto it = std::find_if(m_Container.begin(), m_Container.end(), comparator); it != m_Container.end()) // Find specified Element...
|
||||||
{
|
{
|
||||||
auto element = std::move(*it); // ...move it...
|
auto element = std::move(*it); // ...move it...
|
||||||
|
@ -129,11 +129,11 @@ namespace MWR
|
||||||
/// Clear whole container.
|
/// Clear whole container.
|
||||||
void Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(m_AccessMutex);
|
std::scoped_lock<std::mutex> lock(m_AccessMutex);
|
||||||
m_Container.clear();
|
m_Container.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
mutable std::mutex m_AccessMutex; ///< Mutex for synchronization.
|
mutable std::mutex m_AccessMutex; ///< Mutex for synchronization.
|
||||||
std::vector<T> m_Container; ///< Table of all Elements.
|
std::vector<T> m_Container; ///< Table of all Elements.
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue