Dead
[official-gcc.git] / gomp-20050608-branch / libstdc++-v3 / testsuite / tr1 / 3_function_objects / reference_wrapper / invoke.cc
blobb1eb999c6cf2328a77711a4aa8accda69494e662
1 // 2005-02-27 Douglas Gregor <doug.gregor -at- gmail.com>
2 //
3 // Copyright (C) 2005 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
21 // 2.1 reference wrappers
22 #include <tr1/functional>
23 #include <tr1/type_traits>
24 #include <testsuite_hooks.h>
25 #include <testsuite_tr1.h>
27 using namespace __gnu_test;
29 bool test __attribute__((unused)) = true;
31 struct X
33 typedef int result_type;
35 X() : bar(17) {}
37 int foo(float x) { return truncate_float(x); }
38 int foo_c(float x) const { return truncate_float(x); }
39 int foo_v(float x) volatile { return truncate_float(x); }
40 int foo_cv(float x) const volatile { return truncate_float(x); }
42 int operator()(float x)
44 return foo(x) + 1;
47 int operator()(float x) const
49 return foo_c(x) + 2;
52 int bar;
54 private:
55 X(const X&);
56 X& operator=(const X&);
59 int seventeen() { return 17; }
61 struct get_seventeen
63 typedef int result_type;
64 int operator()() const { return 17; }
67 void test01()
69 using std::tr1::ref;
70 using std::tr1::cref;
72 ::get_seventeen get_sev;
73 ::X x;
74 ::X* xp = &x;
75 int (::X::* p_foo)(float) = &::X::foo;
76 int (::X::* p_foo_c)(float) const = &::X::foo_c;
77 int (::X::* p_foo_v)(float) volatile = &::X::foo_v;
78 int (::X::* p_foo_cv)(float) const volatile = &::X::foo_cv;
79 int ::X::* p_bar = &::X::bar;
81 const float pi = 3.14;
83 // Functions
84 VERIFY(ref(truncate_float)(pi) == 3);
85 VERIFY(ref(seventeen)() == 17);
87 // Function pointers
88 VERIFY(cref(&truncate_float)(pi) == 3);
89 VERIFY(cref(&seventeen)() == 17);
91 // Member function pointers
92 VERIFY(ref(p_foo)(x, pi) == 3);
93 VERIFY(ref(p_foo)(xp, pi) == 3);
94 VERIFY(ref(p_foo_c)(x, pi) == 3);
95 VERIFY(ref(p_foo_c)(xp, pi) == 3);
96 VERIFY(ref(p_foo_v)(x, pi) == 3);
97 VERIFY(ref(p_foo_v)(xp, pi) == 3);
98 VERIFY(ref(p_foo_cv)(x, pi) == 3);
99 VERIFY(ref(p_foo_cv)(xp, pi) == 3);
101 // Member data pointers
102 VERIFY(ref(p_bar)(x) == 17);
103 VERIFY(ref(p_bar)(xp) == 17);
105 // Function objects
106 VERIFY(ref(get_sev)() == 17);
107 VERIFY(cref(get_sev)() == 17);
108 VERIFY(ref(x)(pi) == 4);
109 VERIFY(cref(x)(pi) == 5);
112 int main()
114 test01();
115 return 0;