| 1 |
// { dg-do run { target c++11 } } |
| 2 |
// { dg-require-effective-target hosted } |
| 3 |
|
| 4 |
// Copyright (C) 2010-2025 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 |
// 20.8.15 polymorphic function object wrapper |
| 22 |
|
| 23 |
#include <functional> |
| 24 |
#include <testsuite_hooks.h> |
| 25 |
|
| 26 |
struct Foo |
| 27 |
{ |
| 28 |
Foo() { } |
| 29 |
short operator() ( int && ) { return 1; } |
| 30 |
short operator() ( int && ) const { return 2; } |
| 31 |
short operator() ( int && ) volatile { return 3; } |
| 32 |
short operator() ( int && ) const volatile { return 4; } |
| 33 |
short func( int && ) { return 5; } |
| 34 |
short func_c( int && ) const { return 6; } |
| 35 |
short func_v( int && ) volatile { return 7; } |
| 36 |
short func_cv( int && ) const volatile { return 8; } |
| 37 |
}; |
| 38 |
|
| 39 |
void test01() |
| 40 |
{ |
| 41 |
using std::function; |
| 42 |
using std::ref; |
| 43 |
|
| 44 |
Foo foo; |
| 45 |
Foo const foo_c; |
| 46 |
Foo volatile foo_v; |
| 47 |
Foo const volatile foo_cv; |
| 48 |
|
| 49 |
std::function< int ( int && ) > f1( ref(foo) ); |
| 50 |
VERIFY( f1(0) == 1 ); |
| 51 |
|
| 52 |
std::function< int ( int && ) > f2( ref(foo_c) ); |
| 53 |
VERIFY( f2(0) == 2 ); |
| 54 |
|
| 55 |
std::function< int ( int && ) > f3( ref(foo_v) ); |
| 56 |
VERIFY( f3(0) == 3 ); |
| 57 |
|
| 58 |
std::function< int ( int && ) > f4( ref(foo_cv) ); |
| 59 |
VERIFY( f4(0) == 4 ); |
| 60 |
|
| 61 |
std::function< int ( Foo &, int && ) > f5( &Foo::func ) ; |
| 62 |
VERIFY( f5(foo, 0) == 5 ); |
| 63 |
|
| 64 |
std::function< int ( Foo const &, int && ) > f6( &Foo::func_c ) ; |
| 65 |
VERIFY( f6(foo_c, 0) == 6 ); |
| 66 |
|
| 67 |
std::function< int ( Foo volatile &, int && ) > f7( &Foo::func_v ) ; |
| 68 |
VERIFY( f7(foo_v, 0) == 7 ); |
| 69 |
|
| 70 |
std::function< int ( Foo const volatile &, int && ) > f8( &Foo::func_cv ) ; |
| 71 |
VERIFY( f8(foo_cv, 0) == 8 ); |
| 72 |
} |
| 73 |
|
| 74 |
int main() |
| 75 |
{ |
| 76 |
test01(); |
| 77 |
return 0; |
| 78 |
} |