1 // { dg-do run { target c++11 } }
2 // Copyright (C) 2010-2019 Free Software Foundation, Inc.
3 //
4 // This file is part of the GNU ISO C++ Library.  This library is free
5 // software; you can redistribute it and/or modify it under the
6 // terms of the GNU General Public License as published by the
7 // Free Software Foundation; either version 3, or (at your option)
8 // any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this library; see the file COPYING3.  If not see
17 // <http://www.gnu.org/licenses/>.
18 
19 // 20.8.15 polymorphic function object wrapper
20 
21 #include <functional>
22 #include <testsuite_hooks.h>
23 
24 struct Foo
25 {
FooFoo26   Foo() { }
operator ()Foo27   short operator() ( int && ) { return 1; }
operator ()Foo28   short operator() ( int && ) const { return 2; }
operator ()Foo29   short operator() ( int && ) volatile { return 3; }
operator ()Foo30   short operator() ( int && ) const volatile { return 4; }
funcFoo31   short func( int && ) { return 5; }
func_cFoo32   short func_c( int && ) const { return 6; }
func_vFoo33   short func_v( int && ) volatile { return 7; }
func_cvFoo34   short func_cv( int && ) const volatile { return 8; }
35 };
36 
test01()37 void test01()
38 {
39   using std::function;
40   using std::ref;
41 
42   Foo foo;
43   Foo const foo_c;
44   Foo volatile foo_v;
45   Foo const volatile foo_cv;
46 
47   std::function< int ( int && ) > f1( ref(foo) );
48   VERIFY( f1(0) == 1 );
49 
50   std::function< int ( int && ) > f2( ref(foo_c) );
51   VERIFY( f2(0) == 2 );
52 
53   std::function< int ( int && ) > f3( ref(foo_v) );
54   VERIFY( f3(0) == 3 );
55 
56   std::function< int ( int && ) > f4( ref(foo_cv) );
57   VERIFY( f4(0) == 4 );
58 
59   std::function< int ( Foo &, int && ) > f5( &Foo::func ) ;
60   VERIFY( f5(foo, 0) == 5 );
61 
62   std::function< int ( Foo const &, int && ) > f6( &Foo::func_c ) ;
63   VERIFY( f6(foo_c, 0) == 6 );
64 
65   std::function< int ( Foo volatile &, int && ) > f7( &Foo::func_v ) ;
66   VERIFY( f7(foo_v, 0) == 7 );
67 
68   std::function< int ( Foo const volatile &, int && ) > f8( &Foo::func_cv ) ;
69   VERIFY( f8(foo_cv, 0) == 8 );
70 }
71 
main()72 int main()
73 {
74   test01();
75   return 0;
76 }
77