]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/bind/cv_quals.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / bind / cv_quals.cc
CommitLineData
8d9254fc 1// Copyright (C) 2010-2020 Free Software Foundation, Inc.
8232dc64
PC
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
18// 20.7.11 Function template bind
19
52066eae 20// { dg-do run { target c++11 } }
8232dc64
PC
21
22#include <functional>
23#include <testsuite_hooks.h>
24
1b3fad81
JW
25// target must be invoked with cv-quals of call wrapper
26
8232dc64
PC
27struct X
28{
29 int operator()() { return 0; }
30 int operator()() const { return 1; }
1b3fad81
JW
31 int operator()() volatile { return 2; }
32 int operator()() const volatile { return 3; }
33
34 int operator()(int, int, int) { return 0; }
35 int operator()(int, int, int) const { return 1; }
36 int operator()(int, int, int) volatile { return 2; }
37 int operator()(int, int, int) const volatile { return 3; }
8232dc64
PC
38};
39
1b3fad81
JW
40using std::placeholders::_1;
41using std::placeholders::_2;
42
8232dc64
PC
43void test01()
44{
8232dc64
PC
45 auto b0 = std::bind(X());
46 VERIFY( b0() == 0 );
47
48 const auto b1 = std::bind(X());
49 VERIFY( b1() == 1 );
50
de1d0794 51#if __cplusplus <= 201402L
1b3fad81
JW
52 volatile auto b2 = std::bind(X());
53 VERIFY( b2() == 2 );
54
55 const volatile auto b3 = std::bind(X());
56 VERIFY( b3() == 3 );
de1d0794 57#endif
1b3fad81
JW
58}
59
60void test02()
61{
1b3fad81
JW
62 auto b0 = std::bind<int>(X());
63 VERIFY( b0() == 0 );
64
65 const auto b1 = std::bind<int>(X());
66 VERIFY( b1() == 1 );
67
de1d0794 68#if __cplusplus <= 201402L
1b3fad81
JW
69 volatile auto b2 = std::bind<int>(X());
70 VERIFY( b2() == 2 );
71
72 const volatile auto b3 = std::bind<int>(X());
73 VERIFY( b3() == 3 );
de1d0794 74#endif
1b3fad81
JW
75}
76
77void test03()
78{
1b3fad81
JW
79 auto b0 = std::bind(X(), 0, _1, _2);
80 VERIFY( b0(0, 0) == 0 );
8232dc64 81
1b3fad81
JW
82 const auto b1 = std::bind(X(), _1, 0, _2);
83 VERIFY( b1(0, 0) == 1 );
84
de1d0794 85#if __cplusplus <= 201402L
1b3fad81
JW
86 volatile auto b2 = std::bind(X(), _1, _2, 0);
87 VERIFY( b2(0, 0) == 2 );
88
89 const volatile auto b3 = std::bind(X(), _1, 0, _2);
90 VERIFY( b3(0, 0) == 3 );
de1d0794 91#endif
8232dc64
PC
92}
93
1b3fad81
JW
94void test04()
95{
1b3fad81
JW
96 auto b0 = std::bind<int>(X(), 0, _1, _2);
97 VERIFY( b0(0, 0) == 0 );
98
99 const auto b1 = std::bind<int>(X(), _1, 0, _2);
100 VERIFY( b1(0, 0) == 1 );
101
de1d0794 102#if __cplusplus <= 201402L
1b3fad81
JW
103 volatile auto b2 = std::bind<int>(X(), _1, _2, 0);
104 VERIFY( b2(0, 0) == 2 );
105
106 const volatile auto b3 = std::bind<int>(X(), _1, 0, _2);
107 VERIFY( b3(0, 0) == 3 );
de1d0794 108#endif
1b3fad81
JW
109}
110
111
8232dc64
PC
112int main()
113{
114 test01();
1b3fad81
JW
115 test02();
116 test03();
117 test04();
8232dc64
PC
118 return 0;
119}