specialisations.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // (C) Copyright John Maddock 2000.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. // Simple program to output some template specialisations for the type_traits library.
  7. //
  8. #include <fstream>
  9. using namespace std;
  10. unsigned specializations = 30;
  11. int main()
  12. {
  13. unsigned i, j;
  14. ofstream os("specialisations");
  15. //
  16. // generate is_function tester prototypes:
  17. for(i = 0; i <= specializations; ++i)
  18. {
  19. os << "template <class R";
  20. for(j = 0; j < i; ++j)
  21. {
  22. os << ", class A" << j;
  23. }
  24. os << ">\n::boost::type_traits::yes_type is_function_tester(R (*)(";
  25. if(i == 0)
  26. os << "void";
  27. else
  28. {
  29. for(j = 0; j < i; ++j)
  30. {
  31. if(j) os << ", ";
  32. os << "A" << j;
  33. }
  34. }
  35. os << "));" << endl;
  36. }
  37. os << endl << endl;
  38. //
  39. // generate is_function_helper partial specialisations:
  40. //
  41. for(i = 0; i < specializations; ++i)
  42. {
  43. os << "template <class R";
  44. for(j = 0; j < i; ++j)
  45. {
  46. os << ", class A" << j;
  47. }
  48. os << ">\nstruct is_function_helper_base<R (*)(";
  49. if(i == 0)
  50. os << "void";
  51. else
  52. {
  53. for(j = 0; j < i; ++j)
  54. {
  55. if(j) os << ", ";
  56. os << "A" << j;
  57. }
  58. }
  59. os << ")>{ BOOST_STATIC_CONSTANT(bool, value = true); };" << endl;
  60. }
  61. os << endl << endl;
  62. //
  63. // generate is_member_pointer_helper tester prototypes:
  64. for(i = 0; i <= specializations; ++i)
  65. {
  66. os << "template <class R, class T";
  67. for(j = 0; j < i; ++j)
  68. {
  69. os << ", class A" << j;
  70. }
  71. os << ">\n::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(";
  72. if(i == 0)
  73. os << "void";
  74. else
  75. {
  76. for(j = 0; j < i; ++j)
  77. {
  78. if(j) os << ", ";
  79. os << "A" << j;
  80. }
  81. }
  82. os << "));" << endl;
  83. }
  84. os << endl << endl;
  85. //
  86. // generate is_member_pointer partial specialisations:
  87. //
  88. for(i = 0; i < specializations; ++i)
  89. {
  90. os << "template <class R, class T";
  91. for(j = 0; j < i; ++j)
  92. {
  93. os << ", class A" << j;
  94. }
  95. os << ">\nstruct is_member_pointer<R (T::*)(";
  96. if(i == 0)
  97. os << "void";
  98. else
  99. {
  100. for(j = 0; j < i; ++j)
  101. {
  102. if(j) os << ", ";
  103. os << "A" << j;
  104. }
  105. }
  106. os << ")>{ BOOST_STATIC_CONSTANT(bool, value = true); };" << endl;
  107. }
  108. os << endl << endl;
  109. return 0;
  110. }