pool_construct.m4 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. m4_dnl
  2. m4_dnl Copyright (C) 2000 Stephen Cleary
  3. m4_dnl
  4. m4_dnl Distributed under the Boost Software License, Version 1.0. (See accompany-
  5. m4_dnl ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. m4_dnl
  7. m4_dnl See http://www.boost.org for updates, documentation, and revision history.
  8. m4_dnl
  9. m4_dnl
  10. m4_dnl
  11. m4_dnl Avoid the use of any m4_* identifiers in this header file,
  12. m4_dnl as that may cause incompatibility problems with future
  13. m4_dnl versions of m4.
  14. m4_dnl
  15. m4_dnl This is a normal header file, except that lines starting
  16. m4_dnl with `m4_dnl' will be stripped, TBA_FOR
  17. m4_dnl macros will be replaced with repeated text, and text in
  18. m4_dnl single quotes (`...') will have their single quotes
  19. m4_dnl stripped.
  20. m4_dnl
  21. m4_dnl
  22. m4_dnl Check to make sure NumberOfArguments was defined. If it's not defined,
  23. m4_dnl default to 3
  24. m4_dnl
  25. m4_ifdef(`NumberOfArguments', , `m4_errprint(m4___file__:m4___line__`: NumberOfArguments is not defined; defaulting to 3
  26. ')m4_define(`NumberOfArguments', 3)')m4_dnl
  27. m4_ifelse(NumberOfArguments, , `m4_errprint(m4___file__:m4___line__`: NumberOfArguments is defined to be empty; defaulting to 3
  28. ')m4_define(`NumberOfArguments', 3)')m4_dnl
  29. m4_dnl
  30. m4_dnl Check to make sure NumberOfArguments >= 1. If it's not, then fatal error.
  31. m4_dnl
  32. m4_ifelse(m4_eval(NumberOfArguments < 1), 1, `m4_errprint(m4___file__:m4___line__`: NumberOfArguments ('NumberOfArguments`) is less than 1
  33. ')m4_m4exit(1)')m4_dnl
  34. m4_dnl
  35. m4_dnl Include the BOOST_M4_FOR macro definition
  36. m4_dnl
  37. m4_include(`for.m4')`'m4_dnl
  38. m4_dnl
  39. m4_dnl Begin the generated file.
  40. m4_dnl
  41. // Copyright (C) 2000 Stephen Cleary
  42. //
  43. // Distributed under the Boost Software License, Version 1.0. (See accompany-
  44. // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  45. //
  46. // See http://www.boost.org for updates, documentation, and revision history.
  47. m4_dnl These warnings apply to the file generated from this file.
  48. m4_dnl Of course, you may freely edit this file.
  49. // This file was AUTOMATICALLY GENERATED from "m4___file__"
  50. // Do NOT include directly!
  51. // Do NOT edit!
  52. m4_dnl
  53. m4_dnl First we define a simple 'cv_qual' macro which takes a number, either
  54. m4_dnl 0, 1, 2, or 3, and determines cv-qualification.
  55. m4_dnl
  56. m4_define(`cv_qual',
  57. `m4_ifelse($1, 0, `',
  58. `m4_ifelse($1, 1, `const ',
  59. `m4_ifelse($1, 2, `volatile ',
  60. `m4_ifelse($1, 3, `const volatile ',
  61. `m4_errprint(m4___file__:m4___line__: `Boost m4 script: cv-determiner: Not 0, 1, 2, or 3 (was '$1`)')'
  62. )')')')')m4_dnl
  63. m4_dnl
  64. m4_dnl Next we go through the actual loop. For each number of arguments from
  65. m4_dnl 1 to NumberOfArguments, we create a template function that takes that
  66. m4_dnl many template arguments, and also generate all cv-qualified permutations
  67. m4_dnl of that function.
  68. m4_dnl
  69. BOOST_M4_FOR(N, 1, NumberOfArguments + 1,
  70. `BOOST_M4_FOR(cv, 0, m4_eval(4 ** N),
  71. `template <BOOST_M4_FOR(i, 0, N, `typename T`'i', `, ')>
  72. element_type * construct(BOOST_M4_FOR(i, 0, N,
  73. `cv_qual(m4_eval((cv >> (i * 2)) % 4))T`'i & a`'i', `, '))
  74. {
  75. element_type * const ret = (malloc)();
  76. if (ret == 0)
  77. return ret;
  78. try { new (ret) element_type(BOOST_M4_FOR(i, 0, N, `a`'i', `, ')); }
  79. catch (...) { (free)(ret); throw; }
  80. return ret;
  81. }
  82. ')')