]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/tr1/3_function_objects/bind/mixed.cc
1 // { dg-do run { target c++11 } }
2 // 2011-11-20 Jonathan Wakely <jwakely.gcc -at- gmail.com>
4 // Copyright (C) 2011-2024 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 auto b1
= std::bind(minus
<int>(), 6, p2::_2
);
45 auto b2
= std::tr1::bind(minus
<int>(), 6, p1::_2
);
50 VERIFY( std::tr1::bind(multiplies
<int>(), p1::_1
, b1
)(five
, seven
) == -5 );
51 VERIFY( std::bind(multiplies
<int>(), p2::_1
, b2
)(seven
, five
) == 7 );
53 VERIFY( std::tr1::bind
<int>(multiplies
<int>(), p1::_1
, b1
)(five
, seven
) == -5 );
54 VERIFY( std::bind
<int>(multiplies
<int>(), p2::_1
, b2
)(seven
, five
) == 7 );
56 static_assert( std::is_bind_expression
<decltype(b2
)>::value
,
57 "TR1 bind expression is a std bind expression" );
58 static_assert( std::tr1::is_bind_expression
<decltype(b1
)>::value
,
59 "std bind expression is a TR2 bind expression" );
64 static_assert( std::is_bind_expression
<decltype(c2
)>::value
,
65 "const TR1 bind expression is a std bind expression" );
66 static_assert( std::tr1::is_bind_expression
<decltype(c1
)>::value
,
67 "const std bind expression is a TR2 bind expression" );
69 volatile auto v1
= b1
;
70 volatile auto v2
= b2
;
72 static_assert( std::is_bind_expression
<decltype(v2
)>::value
,
73 "volatile TR1 bind expression is a std bind expression" );
74 static_assert( std::tr1::is_bind_expression
<decltype(v1
)>::value
,
75 "volatile std bind expression is a TR2 bind expression" );
77 const volatile auto cv1
= b1
;
78 const volatile auto cv2
= b2
;
80 static_assert( std::is_bind_expression
<decltype(cv2
)>::value
,
81 "const volatile TR1 bind expression is a std bind expression" );
82 static_assert( std::tr1::is_bind_expression
<decltype(cv1
)>::value
,
83 "const volatile std bind expression is a TR2 bind expression" );
88 auto b1
= std::bind
<int>(minus
<int>(), 6, p2::_2
);
89 auto b2
= std::tr1::bind
<int>(minus
<int>(), 6, p1::_2
);
93 VERIFY( std::tr1::bind(multiplies
<int>(), p1::_1
, b1
)(five
, seven
) == -5 );
94 VERIFY( std::bind(multiplies
<int>(), p2::_1
, b2
)(seven
, five
) == 7 );
96 VERIFY( std::tr1::bind
<int>(multiplies
<int>(), p1::_1
, b1
)(five
, seven
) == -5 );
97 VERIFY( std::bind
<int>(multiplies
<int>(), p2::_1
, b2
)(seven
, five
) == 7 );
99 static_assert( std::is_bind_expression
<decltype(b2
)>::value
,
100 "TR1 bind<R> expression is a std bind expression" );
101 static_assert( std::tr1::is_bind_expression
<decltype(b1
)>::value
,
102 "std bind<R> expression is a TR2 bind expression" );
107 static_assert( std::is_bind_expression
<decltype(c2
)>::value
,
108 "const TR1 bind<R> expression is a std bind expression" );
109 static_assert( std::tr1::is_bind_expression
<decltype(c1
)>::value
,
110 "const std bind<R> expression is a TR2 bind expression" );
112 volatile auto v1
= b1
;
113 volatile auto v2
= b2
;
115 static_assert( std::is_bind_expression
<decltype(v2
)>::value
,
116 "volatile TR1 bind<R> expression is a std bind expression" );
117 static_assert( std::tr1::is_bind_expression
<decltype(v1
)>::value
,
118 "volatile std bind<R> expression is a TR2 bind expression" );
120 const volatile auto cv1
= b1
;
121 const volatile auto cv2
= b2
;
123 static_assert( std::is_bind_expression
<decltype(cv2
)>::value
,
124 "const volatile TR1 bind<R> expression is a std bind expression" );
125 static_assert( std::tr1::is_bind_expression
<decltype(cv1
)>::value
,
126 "const volatile std bind<R> expression is a TR2 bind expression" );