MetaProgramming.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // MetaProgramming.h
  3. //
  4. // Library: Foundation
  5. // Package: Core
  6. // Module: MetaProgramming
  7. //
  8. // Common definitions useful for Meta Template Programming
  9. //
  10. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Foundation_MetaProgramming_INCLUDED
  16. #define Foundation_MetaProgramming_INCLUDED
  17. #include "Poco/Foundation.h"
  18. namespace Poco {
  19. template <typename T>
  20. struct IsReference
  21. /// Use this struct to determine if a template type is a reference.
  22. {
  23. enum
  24. {
  25. VALUE = 0
  26. };
  27. };
  28. template <typename T>
  29. struct IsReference<T&>
  30. {
  31. enum
  32. {
  33. VALUE = 1
  34. };
  35. };
  36. template <typename T>
  37. struct IsReference<const T&>
  38. {
  39. enum
  40. {
  41. VALUE = 1
  42. };
  43. };
  44. template <typename T>
  45. struct IsConst
  46. /// Use this struct to determine if a template type is a const type.
  47. {
  48. enum
  49. {
  50. VALUE = 0
  51. };
  52. };
  53. template <typename T>
  54. struct IsConst<const T&>
  55. {
  56. enum
  57. {
  58. VALUE = 1
  59. };
  60. };
  61. template <typename T>
  62. struct IsConst<const T>
  63. {
  64. enum
  65. {
  66. VALUE = 1
  67. };
  68. };
  69. template <typename T, int i>
  70. struct IsConst<const T[i]>
  71. /// Specialization for const char arrays
  72. {
  73. enum
  74. {
  75. VALUE = 1
  76. };
  77. };
  78. template <typename T>
  79. struct TypeWrapper
  80. /// Use the type wrapper if you want to decouple constness and references from template types.
  81. {
  82. typedef T TYPE;
  83. typedef const T CONSTTYPE;
  84. typedef T& REFTYPE;
  85. typedef const T& CONSTREFTYPE;
  86. };
  87. template <typename T>
  88. struct TypeWrapper<const T>
  89. {
  90. typedef T TYPE;
  91. typedef const T CONSTTYPE;
  92. typedef T& REFTYPE;
  93. typedef const T& CONSTREFTYPE;
  94. };
  95. template <typename T>
  96. struct TypeWrapper<const T&>
  97. {
  98. typedef T TYPE;
  99. typedef const T CONSTTYPE;
  100. typedef T& REFTYPE;
  101. typedef const T& CONSTREFTYPE;
  102. };
  103. template <typename T>
  104. struct TypeWrapper<T&>
  105. {
  106. typedef T TYPE;
  107. typedef const T CONSTTYPE;
  108. typedef T& REFTYPE;
  109. typedef const T& CONSTREFTYPE;
  110. };
  111. } // namespace Poco
  112. #endif // Foundation_MetaProgramming_INCLUDED