1 // { dg-options "-std=gnu++0x" }
2 // 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu>
4 // Copyright (C) 2005-2013 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 // 20.7.15 polymorphic function object wrapper
23 #include <testsuite_hooks.h>
25 using namespace __gnu_test
;
27 bool test
__attribute__((unused
)) = true;
31 struct noncopyable_function_object_type
33 noncopyable_function_object_type(secret
) {}
35 int operator()() const { return 42; }
36 int operator()() { return 17; }
39 noncopyable_function_object_type();
40 noncopyable_function_object_type(const noncopyable_function_object_type
&);
41 void operator=(const noncopyable_function_object_type
&);
44 // Put reference_wrappers into function<> wrappers
52 noncopyable_function_object_type
x(password
);
54 function
<int()> f(ref(x
));
57 VERIFY( f
.target_type() == typeid(noncopyable_function_object_type
) );
58 VERIFY( f
.target
<noncopyable_function_object_type
>() == &x
);
60 function
<int()> g
= f
;
63 VERIFY( g
.target_type() == typeid(noncopyable_function_object_type
) );
64 VERIFY( g
.target
<noncopyable_function_object_type
>() == &x
);
66 function
<int()> h
= cref(x
);
69 VERIFY( h
.target_type() == typeid(noncopyable_function_object_type
) );
70 VERIFY( h
.target
<const noncopyable_function_object_type
>() == &x
);
71 VERIFY( h
.target
<const noncopyable_function_object_type
>() == &x
);
73 const function
<int()>& hc
= h
;
74 VERIFY( h
.target
<noncopyable_function_object_type
>() == 0 );
75 VERIFY( hc
.target
<noncopyable_function_object_type
>() == &x
);