PageRenderTime 25ms CodeModel.GetById 1ms app.highlight 21ms RepoModel.GetById 2ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/phoenix/test/boost_bind_compatibility/bind_cdecl_mf_test.cpp

http://hadesmem.googlecode.com/
C++ | 146 lines | 84 code | 45 blank | 17 comment | 1 complexity | 197427dacf3aceaab486a42111221a41 MD5 | raw file
  1/*==============================================================================
  2    Copyright (c) 2005 Peter Dimov
  3    Copyright (c) 2005-2010 Joel de Guzman
  4    Copyright (c) 2010 Thomas Heller
  5
  6    Distributed under the Boost Software License, Version 1.0. (See accompanying
  7    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  8==============================================================================*/
  9
 10#include <boost/phoenix/core.hpp>
 11#include <boost/phoenix/bind.hpp>
 12#include <boost/detail/lightweight_test.hpp>
 13
 14#include <boost/ref.hpp>
 15
 16struct X
 17{
 18    mutable unsigned int hash;
 19
 20    X(): hash(0) {}
 21
 22    int __cdecl f0() { f1(17); return 0; }
 23    int __cdecl g0() const { g1(17); return 0; }
 24                
 25    int __cdecl f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
 26    int __cdecl g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
 27                
 28    int __cdecl f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
 29    int __cdecl g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
 30                
 31    int __cdecl f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
 32    int __cdecl g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
 33                
 34    int __cdecl f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
 35    int __cdecl g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
 36                
 37    int __cdecl f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
 38    int __cdecl g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
 39                
 40    int __cdecl f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
 41    int __cdecl g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); return 0; }
 42                
 43    int __cdecl f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); return 0; }
 44    int __cdecl g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); return 0; }
 45                
 46    int __cdecl f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { f7(a1, a2, a3, a4, a5, a6, a7); f1(a8); return 0; }
 47    int __cdecl g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); return 0; }
 48};
 49
 50void member_function_test()
 51{
 52    using boost::phoenix::bind;
 53    using boost::phoenix::ref;
 54
 55    X x;
 56
 57    // 0
 58
 59    bind(&X::f0, &x)();
 60    bind(&X::f0, ref(x))();
 61
 62    bind(&X::g0, &x)();
 63    bind(&X::g0, x)();
 64    bind(&X::g0, ref(x))();
 65
 66    // 1
 67
 68    bind(&X::f1, &x, 1)();
 69    bind(&X::f1, ref(x), 1)();
 70
 71    bind(&X::g1, &x, 1)();
 72    bind(&X::g1, x, 1)();
 73    bind(&X::g1, ref(x), 1)();
 74
 75    // 2
 76
 77    bind(&X::f2, &x, 1, 2)();
 78    bind(&X::f2, ref(x), 1, 2)();
 79
 80    bind(&X::g2, &x, 1, 2)();
 81    bind(&X::g2, x, 1, 2)();
 82    bind(&X::g2, ref(x), 1, 2)();
 83
 84    // 3
 85
 86    bind(&X::f3, &x, 1, 2, 3)();
 87    bind(&X::f3, ref(x), 1, 2, 3)();
 88
 89    bind(&X::g3, &x, 1, 2, 3)();
 90    bind(&X::g3, x, 1, 2, 3)();
 91    bind(&X::g3, ref(x), 1, 2, 3)();
 92
 93    // 4
 94
 95    bind(&X::f4, &x, 1, 2, 3, 4)();
 96    bind(&X::f4, ref(x), 1, 2, 3, 4)();
 97
 98    bind(&X::g4, &x, 1, 2, 3, 4)();
 99    bind(&X::g4, x, 1, 2, 3, 4)();
100    bind(&X::g4, ref(x), 1, 2, 3, 4)();
101
102    // 5
103
104    bind(&X::f5, &x, 1, 2, 3, 4, 5)();
105    bind(&X::f5, ref(x), 1, 2, 3, 4, 5)();
106
107    bind(&X::g5, &x, 1, 2, 3, 4, 5)();
108    bind(&X::g5, x, 1, 2, 3, 4, 5)();
109    bind(&X::g5, ref(x), 1, 2, 3, 4, 5)();
110
111    // 6
112
113    bind(&X::f6, &x, 1, 2, 3, 4, 5, 6)();
114    bind(&X::f6, ref(x), 1, 2, 3, 4, 5, 6)();
115
116    bind(&X::g6, &x, 1, 2, 3, 4, 5, 6)();
117    bind(&X::g6, x, 1, 2, 3, 4, 5, 6)();
118    bind(&X::g6, ref(x), 1, 2, 3, 4, 5, 6)();
119
120    // 7
121
122    bind(&X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
123    bind(&X::f7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
124
125    bind(&X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
126    bind(&X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
127    bind(&X::g7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
128
129    // 8
130
131    bind(&X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
132    bind(&X::f8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
133
134    bind(&X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
135    bind(&X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
136    bind(&X::g8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
137
138    BOOST_TEST( x.hash == 23558 );
139}
140
141int main()
142{
143    member_function_test();
144    return boost::report_errors();
145}
146