]>
Commit | Line | Data |
---|---|---|
818ab71a | 1 | // Copyright (C) 2010-2016 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 |
27 | struct 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 |
40 | using std::placeholders::_1; |
41 | using std::placeholders::_2; | |
42 | ||
8232dc64 PC |
43 | void 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 | ||
1b3fad81 JW |
51 | volatile auto b2 = std::bind(X()); |
52 | VERIFY( b2() == 2 ); | |
53 | ||
54 | const volatile auto b3 = std::bind(X()); | |
55 | VERIFY( b3() == 3 ); | |
56 | } | |
57 | ||
58 | void test02() | |
59 | { | |
1b3fad81 JW |
60 | auto b0 = std::bind<int>(X()); |
61 | VERIFY( b0() == 0 ); | |
62 | ||
63 | const auto b1 = std::bind<int>(X()); | |
64 | VERIFY( b1() == 1 ); | |
65 | ||
66 | volatile auto b2 = std::bind<int>(X()); | |
67 | VERIFY( b2() == 2 ); | |
68 | ||
69 | const volatile auto b3 = std::bind<int>(X()); | |
70 | VERIFY( b3() == 3 ); | |
71 | } | |
72 | ||
73 | void test03() | |
74 | { | |
1b3fad81 JW |
75 | auto b0 = std::bind(X(), 0, _1, _2); |
76 | VERIFY( b0(0, 0) == 0 ); | |
8232dc64 | 77 | |
1b3fad81 JW |
78 | const auto b1 = std::bind(X(), _1, 0, _2); |
79 | VERIFY( b1(0, 0) == 1 ); | |
80 | ||
81 | volatile auto b2 = std::bind(X(), _1, _2, 0); | |
82 | VERIFY( b2(0, 0) == 2 ); | |
83 | ||
84 | const volatile auto b3 = std::bind(X(), _1, 0, _2); | |
85 | VERIFY( b3(0, 0) == 3 ); | |
8232dc64 PC |
86 | } |
87 | ||
1b3fad81 JW |
88 | void test04() |
89 | { | |
1b3fad81 JW |
90 | auto b0 = std::bind<int>(X(), 0, _1, _2); |
91 | VERIFY( b0(0, 0) == 0 ); | |
92 | ||
93 | const auto b1 = std::bind<int>(X(), _1, 0, _2); | |
94 | VERIFY( b1(0, 0) == 1 ); | |
95 | ||
96 | volatile auto b2 = std::bind<int>(X(), _1, _2, 0); | |
97 | VERIFY( b2(0, 0) == 2 ); | |
98 | ||
99 | const volatile auto b3 = std::bind<int>(X(), _1, 0, _2); | |
100 | VERIFY( b3(0, 0) == 3 ); | |
101 | } | |
102 | ||
103 | ||
8232dc64 PC |
104 | int main() |
105 | { | |
106 | test01(); | |
1b3fad81 JW |
107 | test02(); |
108 | test03(); | |
109 | test04(); | |
8232dc64 PC |
110 | return 0; |
111 | } |