PageRenderTime 30ms CodeModel.GetById 11ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://hadesmem.googlecode.com/
C++ | 165 lines | 91 code | 47 blank | 27 comment | 2 complexity | 5c87ab988a635fdf4f1f6475f59f53a4 MD5 | raw file
  1/*==============================================================================
  2    Copyright (c) 2005, 2008 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/config.hpp>
 11
 12#if defined(BOOST_MSVC)
 13#pragma warning(disable: 4786)  // identifier truncated in debug info
 14#pragma warning(disable: 4710)  // function not inlined
 15#pragma warning(disable: 4711)  // function selected for automatic inline expansion
 16#pragma warning(disable: 4514)  // unreferenced inline removed
 17#endif
 18
 19#include <boost/phoenix/core.hpp>
 20#include <boost/phoenix/bind.hpp>
 21
 22#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
 23#pragma warning(push, 3)
 24#endif
 25
 26#include <iostream>
 27
 28#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
 29#pragma warning(pop)
 30#endif
 31
 32#include <boost/detail/lightweight_test.hpp>
 33
 34struct X
 35{
 36    mutable unsigned int hash;
 37
 38    X(): hash(0) {}
 39
 40    int f0() { f1(17); return 0; }
 41    int g0() const { g1(17); return 0; }
 42
 43    int f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
 44    int g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
 45
 46    int f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
 47    int g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
 48
 49    int f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
 50    int g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
 51
 52    int f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
 53    int g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
 54
 55    int f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
 56    int g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
 57
 58    int f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
 59    int g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); return 0; }
 60
 61    int 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; }
 62    int 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; }
 63
 64    int 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; }
 65    int 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; }
 66};
 67
 68void member_function_test()
 69{
 70    using boost::phoenix::bind;
 71    using boost::phoenix::ref;
 72
 73    X x;
 74
 75    // 0
 76
 77    bind(&X::f0, &x )();
 78    bind(&X::f0, ref(x) )();
 79
 80    bind(&X::g0, &x )();
 81    bind(&X::g0, x )();
 82    bind(&X::g0, ref(x) )();
 83
 84    // 1
 85
 86    bind(&X::f1, &x, 1 )();
 87    bind(&X::f1, ref(x), 1 )();
 88
 89    bind(&X::g1, &x, 1 )();
 90    bind(&X::g1, x, 1 )();
 91    bind(&X::g1, ref(x), 1 )();
 92
 93    // 2
 94
 95    bind(&X::f2, &x, 1, 2 )();
 96    bind(&X::f2, ref(x), 1, 2 )();
 97
 98    bind(&X::g2, &x, 1, 2 )();
 99    bind(&X::g2, x, 1, 2 )();
100    bind(&X::g2, ref(x), 1, 2 )();
101
102    // 3
103
104    bind(&X::f3, &x, 1, 2, 3 )();
105    bind(&X::f3, ref(x), 1, 2, 3 )();
106
107    bind(&X::g3, &x, 1, 2, 3 )();
108    bind(&X::g3, x, 1, 2, 3 )();
109    bind(&X::g3, ref(x), 1, 2, 3 )();
110
111    // 4
112
113    bind(&X::f4, &x, 1, 2, 3, 4 )();
114    bind(&X::f4, ref(x), 1, 2, 3, 4 )();
115
116    bind(&X::g4, &x, 1, 2, 3, 4 )();
117    bind(&X::g4, x, 1, 2, 3, 4 )();
118    bind(&X::g4, ref(x), 1, 2, 3, 4 )();
119
120    // 5
121
122    bind(&X::f5, &x, 1, 2, 3, 4, 5 )();
123    bind(&X::f5, ref(x), 1, 2, 3, 4, 5 )();
124
125    bind(&X::g5, &x, 1, 2, 3, 4, 5 )();
126    bind(&X::g5, x, 1, 2, 3, 4, 5 )();
127    bind(&X::g5, ref(x), 1, 2, 3, 4, 5 )();
128
129    // 6
130
131    bind(&X::f6, &x, 1, 2, 3, 4, 5, 6 )();
132    bind(&X::f6, ref(x), 1, 2, 3, 4, 5, 6 )();
133
134    bind(&X::g6, &x, 1, 2, 3, 4, 5, 6 )();
135    bind(&X::g6, x, 1, 2, 3, 4, 5, 6 )();
136    bind(&X::g6, ref(x), 1, 2, 3, 4, 5, 6 )();
137
138    // 7
139
140    bind(&X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
141    bind(&X::f7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
142
143    bind(&X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
144    bind(&X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
145    bind(&X::g7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
146
147    // 8
148
149    /*
150    bind(&X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8 )();
151    bind(&X::f8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8 )();
152
153    bind(&X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8 )();
154    bind(&X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8 )();
155    bind(&X::g8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8 )();
156
157    BOOST_TEST( x.hash == 23558 );
158    */
159}
160
161int main()
162{
163    member_function_test();
164    return boost::report_errors();
165}