diff options
Diffstat (limited to 'test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_types.pass.cpp')
-rw-r--r-- | test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_types.pass.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_types.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_types.pass.cpp new file mode 100644 index 000000000000..2b06742a673e --- /dev/null +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/variadic_types.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03 + +// <mutex> + +// template <class Mutex> +// class lock_guard +// { +// public: +// typedef Mutex mutex_type; +// ... +// }; + +#define _LIBCPP_ABI_VARIADIC_LOCK_GUARD +#include <mutex> +#include <type_traits> + +struct NAT {}; + +template <class LG> +auto test_typedef(int) -> typename LG::mutex_type; + +template <class LG> +auto test_typedef(...) -> NAT; + +template <class LG> +constexpr bool has_mutex_type() { + return !std::is_same<decltype(test_typedef<LG>(0)), NAT>::value; +} + +int main() +{ + { + using T = std::lock_guard<>; + static_assert(!has_mutex_type<T>(), ""); + } + { + using M1 = std::mutex; + using T = std::lock_guard<M1>; + static_assert(std::is_same<T::mutex_type, M1>::value, ""); + } + { + using M1 = std::recursive_mutex; + using T = std::lock_guard<M1>; + static_assert(std::is_same<T::mutex_type, M1>::value, ""); + } + { + using M1 = std::mutex; + using M2 = std::recursive_mutex; + using T = std::lock_guard<M1, M2>; + static_assert(!has_mutex_type<T>(), ""); + } + { + using M1 = std::mutex; + using M2 = std::recursive_mutex; + using T = std::lock_guard<M1, M1, M2>; + static_assert(!has_mutex_type<T>(), ""); + } + { + using M1 = std::mutex; + using T = std::lock_guard<M1, M1>; + static_assert(!has_mutex_type<T>(), ""); + } + { + using M1 = std::recursive_mutex; + using T = std::lock_guard<M1, M1, M1>; + static_assert(!has_mutex_type<T>(), ""); + } +} |