]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/tr1/3_function_objects/bind/mixed.cc
1 // { dg-options "-std=gnu++11" }
2 // 2011-11-20 Jonathan Wakely <jwakely.gcc -at- gmail.com>
4 // Copyright (C) 2011-2016 Free Software Foundation, Inc.
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)
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.
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/>.
21 // 3.6 function object binders
22 #include <tr1/functional>
24 #include <testsuite_hooks.h>
26 // std::tr1::bind and std::bind should work together
28 namespace p1
= std::placeholders
;
29 namespace p2
= std::tr1::placeholders
;
31 using std::multiplies
;
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" );
44 bool test
__attribute__((unused
)) = true;
46 auto b1
= std::bind(minus
<int>(), 6, p2::_2
);
47 auto b2
= std::tr1::bind(minus
<int>(), 6, p1::_2
);
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 );
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 );
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" );
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" );
71 volatile auto v1
= b1
;
72 volatile auto v2
= b2
;
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" );
79 const volatile auto cv1
= b1
;
80 const volatile auto cv2
= b2
;
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" );
90 bool test
__attribute__((unused
)) = true;
92 auto b1
= std::bind
<int>(minus
<int>(), 6, p2::_2
);
93 auto b2
= std::tr1::bind
<int>(minus
<int>(), 6, p1::_2
);
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 );
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 );
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" );
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" );
116 volatile auto v1
= b1
;
117 volatile auto v2
= b2
;
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" );
124 const volatile auto cv1
= b1
;
125 const volatile auto cv2
= b2
;
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" );