VS 2017程序无法识别“ scoped_lock” [英] VS 2017 program not recognizing "scoped_lock"
问题描述
我在VS 2017中使用scoped_locked时遇到了问题。我相信我可以追溯到< mutex>
声明,该声明复制如下。什么是最开始禁用 #if
开关以使用scoped_lock的最安全方法?再次感谢。
I've been having issues using scoped_locked in VS 2017. I believe I traced them back to the <mutex>
declaration, copied below. What would be the safest way to disable the #if
switch at the beginning to gain use to scoped_lock? Thanks again.
#if _HAS_CXX17
// CLASS TEMPLATE scoped_lock
template<class... _Mutexes>
class scoped_lock
{ // class with destructor that unlocks mutexes
public:
explicit scoped_lock(_Mutexes&... _Mtxes)
: _MyMutexes(_Mtxes...)
{ // construct and lock
_STD lock(_Mtxes...);
}
explicit scoped_lock(adopt_lock_t, _Mutexes&... _Mtxes)
: _MyMutexes(_Mtxes...)
{ // construct but don't lock
}
~scoped_lock() _NOEXCEPT
{ // unlock all
_For_each_tuple_element(
_MyMutexes,
[](auto& _Mutex) _NOEXCEPT { _Mutex.unlock(); });
}
scoped_lock(const scoped_lock&) = delete;
scoped_lock& operator=(const scoped_lock&) = delete;
private:
tuple<_Mutexes&...> _MyMutexes;
};
推荐答案
从您的问题中不清楚您是否想要禁用/启用此行为。但通常可以使用 / std:c ++ latest
编译器参数和/或覆盖 _HAS_CXX17
来控制它 Visual C ++团队博客。问题在于,没有ovverides时, _HAS_CXX17
的定义取决于 yvals.h
中的编译器版本(请参见这个问题),因此这可能会因Visual Studio的版本而异(所以我可以不会给您一个直接的答案,因为尚不清楚您是否要禁用/启用它,以及确切的Visual Studio版本是什么,哪种组合将为您提供所需的结果。如文章中所述,这样做的缺点是您可能会放弃其他功能,因为它们未提供对STL的精细控制。但是您可以尝试查看恢复为旧的STL行为是否会给您造成问题。
From your question it is not clear if you want to disable/enable this behavior. But in general this can be controlled with the /std:c++latest
compiler argument and/or overriding _HAS_CXX17
as stated in the Visual C++ Team Blog. The issue is that without ovverides the _HAS_CXX17
is defined depending on the compiler version in yvals.h
(see this question) and thus this may vary depending on the version of Visual Studio (so I can't give you a straighforward answer what combo will give you the needed result since it is not clear whether you want to disable/enable it, and what is your exact Visual Studio version). As mentioned in the article, this has the downside that you may loose other features, since they did not provide a fine grained control over the STL. But you can try and see if reverting to the old STL behavior causes issues for you.
这篇关于VS 2017程序无法识别“ scoped_lock”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!