]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/tr1/3_function_objects/bind/mixed.cc
functional (is_placeholder, [...]): Add partial specializations for cv-qualified...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / tr1 / 3_function_objects / bind / mixed.cc
CommitLineData
e02a5443
JW
1// { dg-options "-std=gnu++11" }
2// 2011-11-20 Jonathan Wakely <jwakely.gcc -at- gmail.com>
3//
4// Copyright (C) 2011 Free Software Foundation, Inc.
5//
6// This file is part of the GNU ISO C++ Library. This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 3, or (at your option)
10// any later version.
11//
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License along
18// with this library; see the file COPYING3. If not see
19// <http://www.gnu.org/licenses/>.
20
21// 3.6 function object binders
22#include <tr1/functional>
23#include <functional>
24#include <testsuite_hooks.h>
25
26// std::tr1::bind and std::bind should work together
27
28namespace p1 = std::placeholders;
29namespace p2 = std::tr1::placeholders;
30
31using std::multiplies;
32using std::minus;
33
34void test01()
35{
36 static_assert( std::is_placeholder<decltype(p2::_2)>::value == 2,
37 "TR1 placeholder is a std placeholder" );
38 static_assert( std::tr1::is_placeholder<decltype(p1::_1)>::value == 1,
39 "std placeholder is a TR2 placeholder" );
40}
41
42void test02()
43{
44 bool test __attribute__((unused)) = true;
45
46 auto b1 = std::bind(minus<int>(), 6, p2::_2);
47 auto b2 = std::tr1::bind(minus<int>(), 6, p1::_2);
48
49 int five = 5;
50 int seven = 7;
51
52 VERIFY( std::tr1::bind(multiplies<int>(), p1::_1, b1)(five, seven) == -5 );
53 VERIFY( std::bind(multiplies<int>(), p2::_1, b2)(seven, five) == 7 );
54
55 VERIFY( std::tr1::bind<int>(multiplies<int>(), p1::_1, b1)(five, seven) == -5 );
56 VERIFY( std::bind<int>(multiplies<int>(), p2::_1, b2)(seven, five) == 7 );
57
58 static_assert( std::is_bind_expression<decltype(b2)>::value,
59 "TR1 bind expression is a std bind expression" );
60 static_assert( std::tr1::is_bind_expression<decltype(b1)>::value,
61 "std bind expression is a TR2 bind expression" );
62
63 const auto c1 = b1;
64 const auto c2 = b2;
65
66 static_assert( std::is_bind_expression<decltype(c2)>::value,
67 "const TR1 bind expression is a std bind expression" );
68 static_assert( std::tr1::is_bind_expression<decltype(c1)>::value,
69 "const std bind expression is a TR2 bind expression" );
70
71 volatile auto v1 = b1;
72 volatile auto v2 = b2;
73
74 static_assert( std::is_bind_expression<decltype(v2)>::value,
75 "volatile TR1 bind expression is a std bind expression" );
76 static_assert( std::tr1::is_bind_expression<decltype(v1)>::value,
77 "volatile std bind expression is a TR2 bind expression" );
78
79 const volatile auto cv1 = b1;
80 const volatile auto cv2 = b2;
81
82 static_assert( std::is_bind_expression<decltype(cv2)>::value,
83 "const volatile TR1 bind expression is a std bind expression" );
84 static_assert( std::tr1::is_bind_expression<decltype(cv1)>::value,
85 "const volatile std bind expression is a TR2 bind expression" );
86}
87
88void test03()
89{
90 bool test __attribute__((unused)) = true;
91
92 auto b1 = std::bind<int>(minus<int>(), 6, p2::_2);
93 auto b2 = std::tr1::bind<int>(minus<int>(), 6, p1::_2);
94
95 int five = 5;
96 int seven = 7;
97 VERIFY( std::tr1::bind(multiplies<int>(), p1::_1, b1)(five, seven) == -5 );
98 VERIFY( std::bind(multiplies<int>(), p2::_1, b2)(seven, five) == 7 );
99
100 VERIFY( std::tr1::bind<int>(multiplies<int>(), p1::_1, b1)(five, seven) == -5 );
101 VERIFY( std::bind<int>(multiplies<int>(), p2::_1, b2)(seven, five) == 7 );
102
103 static_assert( std::is_bind_expression<decltype(b2)>::value,
104 "TR1 bind<R> expression is a std bind expression" );
105 static_assert( std::tr1::is_bind_expression<decltype(b1)>::value,
106 "std bind<R> expression is a TR2 bind expression" );
107
108 const auto c1 = b1;
109 const auto c2 = b2;
110
111 static_assert( std::is_bind_expression<decltype(c2)>::value,
112 "const TR1 bind<R> expression is a std bind expression" );
113 static_assert( std::tr1::is_bind_expression<decltype(c1)>::value,
114 "const std bind<R> expression is a TR2 bind expression" );
115
116 volatile auto v1 = b1;
117 volatile auto v2 = b2;
118
119 static_assert( std::is_bind_expression<decltype(v2)>::value,
120 "volatile TR1 bind<R> expression is a std bind expression" );
121 static_assert( std::tr1::is_bind_expression<decltype(v1)>::value,
122 "volatile std bind<R> expression is a TR2 bind expression" );
123
124 const volatile auto cv1 = b1;
125 const volatile auto cv2 = b2;
126
127 static_assert( std::is_bind_expression<decltype(cv2)>::value,
128 "const volatile TR1 bind<R> expression is a std bind expression" );
129 static_assert( std::tr1::is_bind_expression<decltype(cv1)>::value,
130 "const volatile std bind<R> expression is a TR2 bind expression" );
131}
132
133int main()
134{
135 test01();
136 test02();
137 test03();
138 return 0;
139}