all_decl.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // Copyright (C) 2009-2012 Lorenzo Caminiti
  2. // Distributed under the Boost Software License, Version 1.0
  3. // (see accompanying file LICENSE_1_0.txt or a copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Home at http://www.boost.org/libs/local_function
  6. #include <boost/config.hpp>
  7. #ifdef BOOST_NO_CXX11_VARIADIC_MACROS
  8. # error "variadic macros required"
  9. #else
  10. #include <boost/local_function.hpp>
  11. #include <boost/typeof/typeof.hpp>
  12. #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
  13. struct s;
  14. BOOST_TYPEOF_REGISTER_TYPE(s) // Register before binding `this_` below.
  15. // Compile all local function declaration combinations.
  16. struct s {
  17. void f(double p = 1.23, double q = -1.23) {
  18. { // Only params.
  19. void BOOST_LOCAL_FUNCTION(int x, int y, default 0) {
  20. } BOOST_LOCAL_FUNCTION_NAME(l)
  21. l(1);
  22. }
  23. { // Only const binds.
  24. int a, b;
  25. const int& BOOST_LOCAL_FUNCTION(const bind a,
  26. const bind& b, const bind& p, const bind q) {
  27. return b;
  28. } BOOST_LOCAL_FUNCTION_NAME(l)
  29. l();
  30. const s& BOOST_LOCAL_FUNCTION(const bind this_) {
  31. return *this_;
  32. } BOOST_LOCAL_FUNCTION_NAME(t)
  33. t();
  34. const int BOOST_LOCAL_FUNCTION(const bind a,
  35. const bind& b, const bind& p, const bind q,
  36. const bind this_) {
  37. return a;
  38. } BOOST_LOCAL_FUNCTION_NAME(lt)
  39. lt();
  40. }
  41. { // Only plain binds.
  42. int c, d;
  43. int& BOOST_LOCAL_FUNCTION(bind c, bind& d,
  44. bind& p, bind& q) {
  45. return d;
  46. } BOOST_LOCAL_FUNCTION_NAME(l)
  47. l();
  48. s& BOOST_LOCAL_FUNCTION(bind this_) {
  49. return *this_;
  50. } BOOST_LOCAL_FUNCTION_NAME(t)
  51. t();
  52. int BOOST_LOCAL_FUNCTION(bind c, bind& d,
  53. bind& p, bind& q, bind this_) {
  54. return c;
  55. } BOOST_LOCAL_FUNCTION_NAME(lt)
  56. lt();
  57. }
  58. { // Both params and const binds.
  59. int a, b;
  60. void BOOST_LOCAL_FUNCTION(const bind a, const bind& b,
  61. const bind& p, const bind q,
  62. int x, int y, default 0) {
  63. } BOOST_LOCAL_FUNCTION_NAME(l)
  64. l(1);
  65. void BOOST_LOCAL_FUNCTION(const bind this_,
  66. int x, int y, default 0) {
  67. } BOOST_LOCAL_FUNCTION_NAME(t)
  68. t(1);
  69. void BOOST_LOCAL_FUNCTION(const bind a, const bind this_,
  70. const bind& b, const bind& p, const bind q,
  71. int x, int y, default 0) {
  72. } BOOST_LOCAL_FUNCTION_NAME(lt)
  73. lt(1);
  74. }
  75. { // Both params and plain binds.
  76. int c, d;
  77. void BOOST_LOCAL_FUNCTION(bind c, bind& d, bind& p, bind q,
  78. int x, int y, default 0) {
  79. } BOOST_LOCAL_FUNCTION_NAME(l)
  80. l(1);
  81. void BOOST_LOCAL_FUNCTION(bind this_,
  82. int x, int y, default 0) {
  83. } BOOST_LOCAL_FUNCTION_NAME(t)
  84. t(1);
  85. void BOOST_LOCAL_FUNCTION(bind c, bind& d,
  86. bind& p, bind this_, bind q,
  87. int x, int y, default 0) {
  88. } BOOST_LOCAL_FUNCTION_NAME(lt)
  89. lt(1);
  90. }
  91. { // Both const and plain binds.
  92. int a, b, c, d;
  93. void BOOST_LOCAL_FUNCTION(const bind a, const bind& b,
  94. const bind p, bind c, bind& d, bind q) {
  95. } BOOST_LOCAL_FUNCTION_NAME(l)
  96. l();
  97. void BOOST_LOCAL_FUNCTION(const bind this_,
  98. bind c, bind& d, bind q) {
  99. } BOOST_LOCAL_FUNCTION_NAME(ct)
  100. ct();
  101. void BOOST_LOCAL_FUNCTION(const bind this_,
  102. const bind a, const bind& b, const bind p,
  103. bind c, bind& d, bind q) {
  104. } BOOST_LOCAL_FUNCTION_NAME(lct)
  105. lct();
  106. void BOOST_LOCAL_FUNCTION(const bind a, const bind& b,
  107. const bind p, bind this_) {
  108. } BOOST_LOCAL_FUNCTION_NAME(pt)
  109. pt();
  110. void BOOST_LOCAL_FUNCTION(const bind a, const bind& b,
  111. const bind p, bind c, bind this_, bind& d, bind q) {
  112. } BOOST_LOCAL_FUNCTION_NAME(lpt)
  113. lpt();
  114. }
  115. { // All params, const binds, and plain binds.
  116. int a, b, c, d;
  117. void BOOST_LOCAL_FUNCTION(
  118. const bind a, const bind& b, const bind& p,
  119. bind c, bind& d, bind& q, int x, int y, default 0) {
  120. } BOOST_LOCAL_FUNCTION_NAME(l)
  121. l(1);
  122. void BOOST_LOCAL_FUNCTION(const bind this_,
  123. bind c, bind& d, bind& q,
  124. int x, int y, default 0) {
  125. } BOOST_LOCAL_FUNCTION_NAME(ct)
  126. ct(1);
  127. void BOOST_LOCAL_FUNCTION(
  128. const bind a, const bind& b, const bind& p,
  129. bind this_, int x, int y, default 0) {
  130. } BOOST_LOCAL_FUNCTION_NAME(pt)
  131. pt(1);
  132. void BOOST_LOCAL_FUNCTION(const bind a, const bind this_,
  133. const bind& b, const bind& p, bind c, bind& d,
  134. bind& q, int x, int y, default 0) {
  135. } BOOST_LOCAL_FUNCTION_NAME(lct)
  136. lct(1);
  137. void BOOST_LOCAL_FUNCTION(const bind a, const bind& b,
  138. const bind& p, bind c, bind& d, bind this_, bind& q,
  139. int x, int y, default 0) {
  140. } BOOST_LOCAL_FUNCTION_NAME(lpt)
  141. lpt(1);
  142. }
  143. }
  144. };
  145. int main(void) {
  146. s().f();
  147. return 0;
  148. }
  149. #endif // VARIADIC_MACROS