Update copyright in libstdc++-v3.
[official-gcc.git] / libstdc++-v3 / testsuite / 20_util / function / 6.cc
blob4c6c1aee0134f955c41fd390d2b96d699d1d1b0c
1 // { dg-options "-std=gnu++0x" }
2 // 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu>
3 //
4 // Copyright (C) 2005-2013 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.
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
22 #include <functional>
23 #include <testsuite_hooks.h>
25 using namespace __gnu_test;
27 bool test __attribute__((unused)) = true;
29 struct secret {};
31 struct noncopyable_function_object_type
33 noncopyable_function_object_type(secret) {}
35 int operator()() const { return 42; }
36 int operator()() { return 17; }
38 private:
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
45 void test06()
47 using std::function;
48 using std::ref;
49 using std::cref;
51 secret password;
52 noncopyable_function_object_type x(password);
54 function<int()> f(ref(x));
55 VERIFY( f );
56 VERIFY( f() == 17 );
57 VERIFY( f.target_type() == typeid(noncopyable_function_object_type) );
58 VERIFY( f.target<noncopyable_function_object_type>() == &x );
60 function<int()> g = f;
61 VERIFY( g );
62 VERIFY( g() == 17 );
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);
67 VERIFY( h );
68 VERIFY( h() == 42 );
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 );
78 int main()
80 test06();
81 return 0;