Workaround a scoped_lock CTAD problem

See: https://developercommunity.visualstudio.com/content/problem/842917/error-c3538-when-using-scoped-lock-in-derived-temp.html
dependabot/npm_and_yarn/Src/WebController/UI/websocket-extensions-0.1.4
Grzegorz Rychlik 2020-01-02 18:06:28 +01:00
parent b0533d4668
commit 5a36970c3c
1 changed files with 10 additions and 10 deletions

View File

@ -10,7 +10,7 @@ namespace MWR
/// @param comparator function that returns true to keep iterate or false to stop.
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)
if (!comparator(element))
return;
@ -21,7 +21,7 @@ namespace MWR
/// @return Element if existed, otherwise null.
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...
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>
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.
return m_Container.back();
}
@ -47,7 +47,7 @@ namespace MWR
template <typename... 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...
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>
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...
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.
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...
m_Container.erase(it); // ...and remove it.
else
@ -88,7 +88,7 @@ namespace MWR
/// @throw std::invalid_argument on an attempt of removal of a non-existent Element.
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...
m_Container.erase(it); // ...and remove it.
else
@ -101,7 +101,7 @@ namespace MWR
/// @throw std::invalid_argument on an attempt of removal of a non-existent Element.
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...
{
auto element = std::move(*it); // ...move it...
@ -129,11 +129,11 @@ namespace MWR
/// Clear whole container.
void Clear()
{
std::scoped_lock lock(m_AccessMutex);
std::scoped_lock<std::mutex> lock(m_AccessMutex);
m_Container.clear();
}
protected:
private:
mutable std::mutex m_AccessMutex; ///< Mutex for synchronization.
std::vector<T> m_Container; ///< Table of all Elements.
};