]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/30_threads/scoped_lock/cons/deduction.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 30_threads / scoped_lock / cons / deduction.cc
CommitLineData
83ffe9cd 1// Copyright (C) 2017-2023 Free Software Foundation, Inc.
1dd95239
VV
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17
7b936140 18// { dg-do compile { target c++17 } }
1dd95239 19
af181c91
JW
20#include <mutex>
21
22template<typename T, typename U> struct require_same;
23template<typename T> struct require_same<T, T> { using type = void; };
1dd95239 24
af181c91
JW
25template<typename T, typename U>
26 typename require_same<T, U>::type
27 check_type(U&) { }
28
29void
30test01()
1dd95239 31{
af181c91
JW
32 std::scoped_lock l0;
33 check_type<std::scoped_lock<>>(l0);
34
35 struct BasicLockable {
36 void lock() { }
37 void unlock() { }
38 } m1;
39
40 std::scoped_lock l1(m1);
41 check_type<std::scoped_lock<BasicLockable>>(l1);
42
43 struct Lockable {
44 void lock() { }
45 void unlock() { }
46 bool try_lock() { return true; }
47 } m2;
48
49 std::mutex m3;
50 std::scoped_lock l2(m2, m3);
51 check_type<std::scoped_lock<Lockable, std::mutex>>(l2);
1dd95239 52}
e12d3780
JW
53
54void
55test02()
56{
57 std::scoped_lock l0(std::adopt_lock);
58 check_type<std::scoped_lock<>>(l0);
59
60 struct BasicLockable {
61 void lock() { }
62 void unlock() { }
63 } m1;
64
65 std::scoped_lock l1(std::adopt_lock, m1);
66 check_type<std::scoped_lock<BasicLockable>>(l1);
67
68 struct Lockable {
69 void lock() { }
70 void unlock() { }
71 bool try_lock() { return true; }
72 } m2;
73
74 std::mutex m3;
75 std::scoped_lock l2(std::adopt_lock, m2, m3);
76 check_type<std::scoped_lock<Lockable, std::mutex>>(l2);
77}