You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

352 lines
12 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: stlsoft/util/compiler_optimisation_traits.hpp (was stlsoft_compiler_traits.h)
  3. *
  4. * Purpose: compiler_optimisation_traits class.
  5. *
  6. * Created: 15th November 2003
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2003-2009, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file stlsoft/util/compiler_optimisation_traits.hpp
  40. *
  41. * \brief [C++ only] Definition of the stlsoft::compiler_optimisation_traits
  42. * traits class
  43. * (\ref group__library__utility "Utility" Library).
  44. */
  45. #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_COMPILER_OPTIMISATION_TRAITS
  46. #define STLSOFT_INCL_STLSOFT_UTIL_HPP_COMPILER_OPTIMISATION_TRAITS
  47. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  48. # define STLSOFT_VER_H_STLSOFT_COMPILER_OPTIMISATION_TRAITS_MAJOR 4
  49. # define STLSOFT_VER_H_STLSOFT_COMPILER_OPTIMISATION_TRAITS_MINOR 0
  50. # define STLSOFT_VER_H_STLSOFT_COMPILER_OPTIMISATION_TRAITS_REVISION 1
  51. # define STLSOFT_VER_H_STLSOFT_COMPILER_OPTIMISATION_TRAITS_EDIT 21
  52. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  53. /* /////////////////////////////////////////////////////////////////////////
  54. * Includes
  55. */
  56. #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
  57. # include <stlsoft/stlsoft.h>
  58. #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
  59. /* /////////////////////////////////////////////////////////////////////////
  60. * Namespace
  61. */
  62. #ifndef _STLSOFT_NO_NAMESPACE
  63. namespace stlsoft
  64. {
  65. #endif /* _STLSOFT_NO_NAMESPACE */
  66. /* /////////////////////////////////////////////////////////////////////////
  67. * Classes
  68. */
  69. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  70. /** \brief The base class, and the comparand for empty cases
  71. *
  72. * \ingroup group__library__utility
  73. *
  74. */
  75. struct compiler_optimisation_traits_ebo_parent
  76. {};
  77. /* EBO - Empty Base Optimisation
  78. */
  79. /** \brief The result of Case 1, and the intermediate parent for Cases 3 & 4.
  80. *
  81. * \ingroup group__library__utility
  82. *
  83. * compiler_optimisation_traits_ebo_parent
  84. * |
  85. * V
  86. * compiler_optimisation_traits_ebo_thin_child
  87. *
  88. */
  89. struct compiler_optimisation_traits_ebo_thin_child
  90. : compiler_optimisation_traits_ebo_parent
  91. {};
  92. /** \brief The result of Case 2
  93. *
  94. * \ingroup group__library__utility
  95. *
  96. * compiler_optimisation_traits_ebo_parent
  97. * |
  98. * V
  99. * compiler_optimisation_traits_ebo_thick_child
  100. *
  101. */
  102. struct compiler_optimisation_traits_ebo_thick_child
  103. : compiler_optimisation_traits_ebo_parent
  104. {
  105. int i;
  106. };
  107. /** \brief Used in Cases 2, 4, 6 & 8
  108. *
  109. * \ingroup group__library__utility
  110. *
  111. */
  112. struct compiler_optimisation_traits_ebo_thick_peer
  113. {
  114. int i;
  115. };
  116. /** \brief The result of Case 3
  117. *
  118. * \ingroup group__library__utility
  119. *
  120. * compiler_optimisation_traits_ebo_parent
  121. * |
  122. * V
  123. * compiler_optimisation_traits_ebo_thin_child
  124. * |
  125. * V
  126. * compiler_optimisation_traits_ebo_thin_grandchild
  127. *
  128. */
  129. struct compiler_optimisation_traits_ebo_thin_grandchild
  130. : compiler_optimisation_traits_ebo_thin_child
  131. {};
  132. /** \brief The result of Case 4
  133. *
  134. * \ingroup group__library__utility
  135. *
  136. * compiler_optimisation_traits_ebo_parent
  137. * |
  138. * V
  139. * compiler_optimisation_traits_ebo_thin_child
  140. * |
  141. * V
  142. * compiler_optimisation_traits_ebo_thick_grandchild
  143. *
  144. */
  145. struct compiler_optimisation_traits_ebo_thick_grandchild
  146. : compiler_optimisation_traits_ebo_thin_child
  147. {
  148. int i;
  149. };
  150. /** \brief Used in Case 5
  151. *
  152. * \ingroup group__library__utility
  153. *
  154. */
  155. struct compiler_optimisation_traits_ebo_parent2
  156. {};
  157. /** \brief The result of Case 5
  158. *
  159. * \ingroup group__library__utility
  160. *
  161. * compiler_optimisation_traits_ebo_parent compiler_optimisation_traits_ebo_parent2
  162. * | |
  163. * V V
  164. * compiler_optimisation_traits_ebo_mi_thin_child
  165. *
  166. */
  167. struct compiler_optimisation_traits_ebo_mi_thin_child
  168. : compiler_optimisation_traits_ebo_parent, compiler_optimisation_traits_ebo_parent2
  169. {};
  170. /** \brief The result of Case 6
  171. *
  172. * \ingroup group__library__utility
  173. *
  174. * compiler_optimisation_traits_ebo_parent compiler_optimisation_traits_ebo_parent2
  175. * | |
  176. * V V
  177. * compiler_optimisation_traits_ebo_mi_thick_child
  178. *
  179. */
  180. struct compiler_optimisation_traits_ebo_mi_thick_child
  181. : compiler_optimisation_traits_ebo_parent, compiler_optimisation_traits_ebo_parent2
  182. {
  183. int i;
  184. };
  185. /** \brief The result of Case 7
  186. *
  187. * \ingroup group__library__utility
  188. *
  189. * compiler_optimisation_traits_ebo_parent compiler_optimisation_traits_ebo_thick_peer
  190. * | |
  191. * V V
  192. * compiler_optimisation_traits_ebo_mi_mixin_child
  193. *
  194. */
  195. struct compiler_optimisation_traits_ebo_mi_mixin_child
  196. : compiler_optimisation_traits_ebo_parent, compiler_optimisation_traits_ebo_thick_peer
  197. {};
  198. /* EDO - Empty Derived Optimisation
  199. */
  200. /** \brief Used in Case 1
  201. *
  202. * \ingroup group__library__utility
  203. *
  204. */
  205. struct compiler_optimisation_traits_edo_thin_base
  206. {};
  207. /** \brief Used in Case 2
  208. *
  209. * \ingroup group__library__utility
  210. *
  211. */
  212. struct compiler_optimisation_traits_edo_thick_base
  213. {
  214. int i;
  215. };
  216. /** \brief Used in Case 3
  217. *
  218. * \ingroup group__library__utility
  219. *
  220. */
  221. struct compiler_optimisation_traits_edo_thin_base2
  222. {};
  223. /** \brief Used in Cases 3 & 4
  224. *
  225. * \ingroup group__library__utility
  226. *
  227. */
  228. template <ss_typename_param_k T>
  229. struct compiler_optimisation_traits_edo_child
  230. : T
  231. {};
  232. /** \brief Result of case 3
  233. *
  234. * \ingroup group__library__utility
  235. *
  236. * compiler_optimisation_traits_edo_thick_base
  237. * |
  238. * V
  239. * compiler_optimisation_traits_edo_child_of_thick_base
  240. *
  241. */
  242. struct compiler_optimisation_traits_edo_child_of_thick_base
  243. : compiler_optimisation_traits_edo_thick_base
  244. {};
  245. /** \brief Used in Cases 7 & 8
  246. *
  247. * \ingroup group__library__utility
  248. *
  249. */
  250. template< ss_typename_param_k T1
  251. , ss_typename_param_k T2
  252. >
  253. struct compiler_optimisation_traits_edo_mi_child
  254. : T1, T2
  255. {};
  256. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  257. /** \brief traits class for (current) compiler
  258. *
  259. * \ingroup group__library__utility
  260. *
  261. */
  262. struct compiler_optimisation_traits
  263. {
  264. public:
  265. // Empty Base Optimisation (EBO)
  266. //
  267. /// 1. With empty base and empty child
  268. enum { supportsEBO1 = sizeof(compiler_optimisation_traits_ebo_thin_child) == sizeof(compiler_optimisation_traits_ebo_parent) };
  269. /// 2. With empty base and non-empty child
  270. enum { supportsEBO2 = sizeof(compiler_optimisation_traits_ebo_thick_child) == sizeof(compiler_optimisation_traits_ebo_thick_peer) };
  271. /// 3. With empty base, empty intermediate, and empty child
  272. enum { supportsEBO3 = sizeof(compiler_optimisation_traits_ebo_thin_grandchild) == sizeof(compiler_optimisation_traits_ebo_parent) };
  273. /// 4. With empty base, empty intermediate, and non-empty child
  274. enum { supportsEBO4 = sizeof(compiler_optimisation_traits_ebo_thick_grandchild) == sizeof(compiler_optimisation_traits_ebo_thick_peer) };
  275. /// 5. With two empty bases and empty child
  276. enum { supportsEBO5 = sizeof(compiler_optimisation_traits_ebo_mi_thin_child) == sizeof(compiler_optimisation_traits_ebo_parent) };
  277. /// 6. With two empty bases and non-empty child
  278. enum { supportsEBO6 = sizeof(compiler_optimisation_traits_ebo_mi_thick_child) == sizeof(compiler_optimisation_traits_ebo_thick_peer) };
  279. /// 7. With one empty base (the mixin), one non-empty base and empty child
  280. enum { supportsEBO7 = sizeof(compiler_optimisation_traits_ebo_mi_mixin_child) == sizeof(compiler_optimisation_traits_ebo_thick_peer) };
  281. enum { supportsEBO = supportsEBO1 & supportsEBO2 & supportsEBO3 & supportsEBO4 };
  282. enum { supportsMIEBO = supportsEBO5 & supportsEBO6 & supportsEBO7 /* & supportsEBO8 */ };
  283. enum { supportsExtendedEBO = supportsEBO & supportsMIEBO };
  284. // Empty Derived Optimisation (EDO)
  285. //
  286. /// 1. With empty base (same as EBO1)
  287. enum { supportsEDO1 = supportsEBO1 };
  288. /// 2. With empty base (same as EBO1); child is template
  289. enum { supportsEDO2 = sizeof(compiler_optimisation_traits_edo_child<compiler_optimisation_traits_edo_thin_base>) == sizeof(compiler_optimisation_traits_edo_thin_base) };
  290. /// 3. With non-empty base
  291. enum { supportsEDO3 = sizeof(compiler_optimisation_traits_edo_child_of_thick_base) == sizeof(compiler_optimisation_traits_edo_thick_base) };
  292. /// 4. With non-empty base; child is template
  293. enum { supportsEDO4 = sizeof(compiler_optimisation_traits_edo_child<compiler_optimisation_traits_edo_thick_base>) == sizeof(compiler_optimisation_traits_edo_thick_base) };
  294. /// 5. With two empty bases
  295. enum { supportsEDO5 = supportsEBO5 };
  296. /// 6. With two empty bases; child is template
  297. enum { supportsEDO6 = sizeof(compiler_optimisation_traits_edo_mi_child<compiler_optimisation_traits_edo_thin_base, compiler_optimisation_traits_edo_thin_base2>) == sizeof(compiler_optimisation_traits_edo_thin_base) };
  298. /// 7. With one empty base (the mixin), one non-empty base
  299. enum { supportsEDO7 = supportsEBO7 };
  300. /// 8. With one empty base (the mixin), one non-empty base; child is template
  301. enum { supportsEDO8 = sizeof(compiler_optimisation_traits_edo_mi_child<compiler_optimisation_traits_edo_thick_base, compiler_optimisation_traits_edo_thin_base>) == sizeof(compiler_optimisation_traits_edo_thick_base) };
  302. enum { supportsEDO = supportsEDO1 & supportsEDO2 & supportsEDO3 & supportsEDO4 };
  303. enum { supportsMIEDO = supportsEDO5 & supportsEDO6 & supportsEDO7 & supportsEDO8 };
  304. enum { supportsExtendedEDO = supportsEDO & supportsMIEDO };
  305. };
  306. /* ////////////////////////////////////////////////////////////////////// */
  307. #ifndef _STLSOFT_NO_NAMESPACE
  308. } // namespace stlsoft
  309. #endif /* _STLSOFT_NO_NAMESPACE */
  310. /* ////////////////////////////////////////////////////////////////////// */
  311. #endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_COMPILER_OPTIMISATION_TRAITS */
  312. /* ///////////////////////////// end of file //////////////////////////// */