1// { dg-options "-std=gnu++11" } 2// Copyright (C) 2010-2015 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 24struct Foo 25{ 26 Foo() { } 27 short operator() ( int && ) { return 1; } 28 short operator() ( int && ) const { return 2; } 29 short operator() ( int && ) volatile { return 3; } 30 short operator() ( int && ) const volatile { return 4; } 31 short func( int && ) { return 5; } 32 short func_c( int && ) const { return 6; } 33 short func_v( int && ) volatile { return 7; } 34 short func_cv( int && ) const volatile { return 8; } 35}; 36 37void test01() 38{ 39 bool test __attribute__((unused)) = true; 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 74int main() 75{ 76 test01(); 77 return 0; 78} 79