| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | //====================================================================================================================== | ||
| 2 | //! @file | ||
| 3 | /* | ||
| 4 | TTS - Tiny Test System | ||
| 5 | Copyright : TTS Contributors & Maintainers | ||
| 6 | SPDX-License-Identifier: BSL-1.0 | ||
| 7 | */ | ||
| 8 | //====================================================================================================================== | ||
| 9 | #pragma once | ||
| 10 | |||
| 11 | #include <tts/tools/comparators.hpp> | ||
| 12 | #include <tts/tools/as_text.hpp> | ||
| 13 | #include <tts/engine/info.hpp> | ||
| 14 | #include <tts/engine/check.hpp> | ||
| 15 | #include <tts/tools/typename.hpp> | ||
| 16 | |||
| 17 | namespace tts::_ | ||
| 18 | { | ||
| 19 | template<typename A, typename B> | ||
| 20 | 12 | logger relation_failed(A const& a, B const& b, check_site const& site, char const* kind) | |
| 21 | { | ||
| 22 | 36 | return check_failed(site, | |
| 23 | ::tts::text {"%s: %s %s %s is false because %s %s %s.", | ||
| 24 | kind, | ||
| 25 | 12 | site.lhs, | |
| 26 | 12 | site.op, | |
| 27 | 12 | site.rhs, | |
| 28 |
1/1✓ Branch 1 taken 10 times.
|
24 | ::tts::as_text(a).data(), |
| 29 | 12 | site.negated, | |
| 30 |
2/3✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
|
48 | ::tts::as_text(b).data()}); |
| 31 | ✗ | } | |
| 32 | |||
| 33 | template<typename Relation, typename A, typename B> | ||
| 34 | 1623 | logger check_relation(Relation relation, A const& a, B const& b, check_site const& site) | |
| 35 | { | ||
| 36 |
3/3✓ Branch 1 taken 835 times.
✓ Branch 3 taken 806 times.
✓ Branch 4 taken 10 times.
|
1623 | if(relation(a, b)) |
| 37 | { | ||
| 38 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 824 times.
|
1605 | if(check_passed()) |
| 39 |
1/1✓ Branch 1 taken 1 times.
|
2 | check_report(site, |
| 40 | 2 | ::tts::text {"Expression: %s %s %s is true.", site.lhs, site.op, site.rhs}); | |
| 41 | 1605 | return logger {false}; | |
| 42 | } | ||
| 43 | |||
| 44 |
1/1✓ Branch 1 taken 10 times.
|
18 | return relation_failed(a, b, site, "Expression"); |
| 45 | ✗ | } | |
| 46 | |||
| 47 | 18 | template<typename A, typename B> logger types_differ(check_site const& site) | |
| 48 | { | ||
| 49 | 36 | return check_failed(site, | |
| 50 | ::tts::text {"'%s %s %s' is false because '%.*s' is not '%.*s'.", | ||
| 51 | 18 | site.lhs, | |
| 52 | 18 | site.op, | |
| 53 | 18 | site.rhs, | |
| 54 | ::tts::typename_<A>.size(), | ||
| 55 | ::tts::typename_<A>.data(), | ||
| 56 | ::tts::typename_<B>.size(), | ||
| 57 |
1/1✓ Branch 1 taken 12 times.
|
36 | ::tts::typename_<B>.data()}); |
| 58 | ✗ | } | |
| 59 | |||
| 60 | template<typename Relation, typename A, typename B> | ||
| 61 | 74 | logger check_typed_relation(Relation relation, A const& a, B const& b, check_site const& site) | |
| 62 | { | ||
| 63 |
1/1✓ Branch 1 taken 12 times.
|
24 | if constexpr(!std::same_as<A, B>) return types_differ<A, B>(site); |
| 64 |
1/1✓ Branch 1 taken 29 times.
|
50 | else return check_relation(relation, a, b, site); |
| 65 | ✗ | } | |
| 66 | |||
| 67 | template<bool Holds, typename A, typename B> | ||
| 68 | 34 | logger check_constant_relation(A const& a, B const& b, check_site const& site) | |
| 69 | { | ||
| 70 | if constexpr(Holds) | ||
| 71 | { | ||
| 72 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
|
34 | if(check_passed()) |
| 73 | ✗ | check_report( | |
| 74 | ✗ | site, ::tts::text {"Constant expression: %s %s %s is true.", site.lhs, site.op, site.rhs}); | |
| 75 | 34 | return logger {false}; | |
| 76 | } | ||
| 77 | else | ||
| 78 | { | ||
| 79 | return relation_failed(a, b, site, "Constant expression"); | ||
| 80 | } | ||
| 81 | ✗ | } | |
| 82 | |||
| 83 | template<bool Holds, typename A, typename B> | ||
| 84 | 12 | logger check_typed_constant_relation(A const& a, B const& b, check_site const& site) | |
| 85 | { | ||
| 86 | if constexpr(!std::same_as<A, B>) return types_differ<A, B>(site); | ||
| 87 |
1/1✓ Branch 1 taken 12 times.
|
12 | else return check_constant_relation<Holds>(a, b, site); |
| 88 | ✗ | } | |
| 89 | } | ||
| 90 | |||
| 91 | #define TTS_RELATION(A, B, OP, T, F, ...) TTS_RELATION_##__VA_ARGS__(A, B, OP, T, F) | ||
| 92 | #define TTS_RELATION_(A, B, OP, T, F) TTS_RELATION_IMPL(A, B, OP, T, F, TTS_FAIL) | ||
| 93 | #define TTS_RELATION_REQUIRED(A, B, OP, T, F) TTS_RELATION_IMPL(A, B, OP, T, F, TTS_FATAL) | ||
| 94 | |||
| 95 | #define TTS_RELATION_IMPL(A, B, OP, T, F, FAILURE) \ | ||
| 96 | ::tts::_::check_relation( \ | ||
| 97 | ::tts::_::OP, A, B, TTS_CHECK_SITE(FAILURE, TTS_STRING(A), T, TTS_STRING(B), F)) /**/ | ||
| 98 | |||
| 99 | //====================================================================================================================== | ||
| 100 | /** | ||
| 101 | @defgroup test-relation Relation Tests Macros | ||
| 102 | @brief Macros for performing relation checks. | ||
| 103 | @{ | ||
| 104 | **/ | ||
| 105 | //====================================================================================================================== | ||
| 106 | |||
| 107 | //====================================================================================================================== | ||
| 108 | /** | ||
| 109 | @name Runtime Relation Checks | ||
| 110 | @{ | ||
| 111 | **/ | ||
| 112 | //====================================================================================================================== | ||
| 113 | |||
| 114 | //====================================================================================================================== | ||
| 115 | /** | ||
| 116 | @def TTS_BIT_EQUAL | ||
| 117 | @brief Performs equality comparison between the bits of two expressions | ||
| 118 | |||
| 119 | This comparison goes through the `bit_equal` member of tts::comparison, a `memcmp` over the whole | ||
| 120 | object unless the type specializes it. | ||
| 121 | |||
| 122 | @param LHS, RHS Expressions to compare. | ||
| 123 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 124 | |||
| 125 | @groupheader{Example} | ||
| 126 | @snippet doc/bit_equal.cpp snippet | ||
| 127 | **/ | ||
| 128 | //====================================================================================================================== | ||
| 129 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 130 | #define TTS_BIT_EQUAL(LHS, RHS, ...) | ||
| 131 | #else | ||
| 132 | #define TTS_BIT_EQUAL(LHS, RHS, ...) TTS_RELATION(LHS, RHS, bit_eq, "==", "!=", __VA_ARGS__) | ||
| 133 | #endif | ||
| 134 | |||
| 135 | //====================================================================================================================== | ||
| 136 | /** | ||
| 137 | @def TTS_BIT_NOT_EQUAL | ||
| 138 | @brief Performs inequality comparison between the bits of two expressions | ||
| 139 | |||
| 140 | This comparison goes through the `bit_equal` member of tts::comparison, a `memcmp` over the whole | ||
| 141 | object unless the type specializes it. | ||
| 142 | |||
| 143 | @param LHS, RHS Expressions to compare. | ||
| 144 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 145 | |||
| 146 | @groupheader{Example} | ||
| 147 | @snippet doc/bit_not_equal.cpp snippet | ||
| 148 | **/ | ||
| 149 | //====================================================================================================================== | ||
| 150 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 151 | #define TTS_BIT_NOT_EQUAL(LHS, RHS, ...) | ||
| 152 | #else | ||
| 153 | #define TTS_BIT_NOT_EQUAL(LHS, RHS, ...) TTS_RELATION(LHS, RHS, bit_neq, "!=", "==", __VA_ARGS__) | ||
| 154 | #endif | ||
| 155 | |||
| 156 | //====================================================================================================================== | ||
| 157 | /** | ||
| 158 | @def TTS_EQUAL | ||
| 159 | @brief Performs equality comparison between two expressions | ||
| 160 | |||
| 161 | This comparison is performed by using the proper `operator==` overload or by a | ||
| 162 | [custom comparison](@ref customize-comparison). | ||
| 163 | |||
| 164 | @param LHS, RHS Expressions to compare. | ||
| 165 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 166 | |||
| 167 | |||
| 168 | @groupheader{Example} | ||
| 169 | @snippet doc/equal.cpp snippet | ||
| 170 | **/ | ||
| 171 | //====================================================================================================================== | ||
| 172 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 173 | #define TTS_EQUAL(LHS, RHS, ...) | ||
| 174 | #else | ||
| 175 | #define TTS_EQUAL(LHS, RHS, ...) TTS_RELATION(LHS, RHS, eq, "==", "!=", __VA_ARGS__) | ||
| 176 | #endif | ||
| 177 | |||
| 178 | //====================================================================================================================== | ||
| 179 | /** | ||
| 180 | @def TTS_NOT_EQUAL | ||
| 181 | @brief Performs inequality comparison between two expressions | ||
| 182 | |||
| 183 | This comparison is performed by using the proper `operator==` overload or by a | ||
| 184 | [custom comparison](@ref customize-comparison). | ||
| 185 | |||
| 186 | @param LHS, RHS Expressions to compare. | ||
| 187 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 188 | |||
| 189 | @groupheader{Example} | ||
| 190 | @snippet doc/not_equal.cpp snippet | ||
| 191 | **/ | ||
| 192 | //====================================================================================================================== | ||
| 193 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 194 | #define TTS_NOT_EQUAL(LHS, RHS, ...) | ||
| 195 | #else | ||
| 196 | #define TTS_NOT_EQUAL(LHS, RHS, ...) TTS_RELATION(LHS, RHS, neq, "!=", "==", __VA_ARGS__) | ||
| 197 | #endif | ||
| 198 | |||
| 199 | //====================================================================================================================== | ||
| 200 | /** | ||
| 201 | @def TTS_LESS | ||
| 202 | @brief Performs less-than comparison between two expressions | ||
| 203 | |||
| 204 | This comparison is performed by using the proper `operator<` overload or by a | ||
| 205 | [custom comparison](@ref customize-comparison). | ||
| 206 | |||
| 207 | @param LHS, RHS Expressions to compare. | ||
| 208 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 209 | |||
| 210 | @groupheader{Example} | ||
| 211 | @snippet doc/less.cpp snippet | ||
| 212 | **/ | ||
| 213 | //====================================================================================================================== | ||
| 214 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 215 | #define TTS_LESS(LHS, RHS, ...) | ||
| 216 | #else | ||
| 217 | #define TTS_LESS(LHS, RHS, ...) TTS_RELATION(LHS, RHS, lt, "<", ">=", __VA_ARGS__) | ||
| 218 | #endif | ||
| 219 | |||
| 220 | //====================================================================================================================== | ||
| 221 | /** | ||
| 222 | @def TTS_GREATER | ||
| 223 | @brief Performs greater-than comparison between two expressions | ||
| 224 | |||
| 225 | This comparison is performed by using the proper `operator<` overload or by a | ||
| 226 | [custom comparison](@ref customize-comparison). | ||
| 227 | |||
| 228 | @param LHS, RHS Expressions to compare. | ||
| 229 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 230 | |||
| 231 | @groupheader{Example} | ||
| 232 | @snippet doc/greater.cpp snippet | ||
| 233 | **/ | ||
| 234 | //====================================================================================================================== | ||
| 235 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 236 | #define TTS_GREATER(LHS, RHS, ...) | ||
| 237 | #else | ||
| 238 | #define TTS_GREATER(LHS, RHS, ...) TTS_RELATION(LHS, RHS, gt, ">", "<=", __VA_ARGS__) | ||
| 239 | #endif | ||
| 240 | |||
| 241 | //====================================================================================================================== | ||
| 242 | /** | ||
| 243 | @def TTS_LESS_EQUAL | ||
| 244 | @brief Performs less-or-equal-than comparison between two expressions | ||
| 245 | |||
| 246 | This comparison is performed by using the proper `operator<` overload or by a | ||
| 247 | [custom comparison](@ref customize-comparison). | ||
| 248 | |||
| 249 | @param LHS, RHS Expressions to compare. | ||
| 250 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 251 | |||
| 252 | @groupheader{Example} | ||
| 253 | @snippet doc/less_equal.cpp snippet | ||
| 254 | **/ | ||
| 255 | //====================================================================================================================== | ||
| 256 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 257 | #define TTS_LESS_EQUAL(LHS, RHS, ...) | ||
| 258 | #else | ||
| 259 | #define TTS_LESS_EQUAL(LHS, RHS, ...) TTS_RELATION(LHS, RHS, le, "<=", ">", __VA_ARGS__) | ||
| 260 | #endif | ||
| 261 | |||
| 262 | //====================================================================================================================== | ||
| 263 | /** | ||
| 264 | @def TTS_GREATER_EQUAL | ||
| 265 | @brief Performs greater-or-equal-than comparison between two expressions | ||
| 266 | |||
| 267 | This comparison is performed by using the proper `operator<` overload or by a | ||
| 268 | [custom comparison](@ref customize-comparison). | ||
| 269 | |||
| 270 | @param LHS, RHS Expressions to compare. | ||
| 271 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 272 | |||
| 273 | @groupheader{Example} | ||
| 274 | @snippet doc/greater_equal.cpp snippet | ||
| 275 | **/ | ||
| 276 | //====================================================================================================================== | ||
| 277 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 278 | #define TTS_GREATER_EQUAL(LHS, RHS, ...) | ||
| 279 | #else | ||
| 280 | #define TTS_GREATER_EQUAL(LHS, RHS, ...) TTS_RELATION(LHS, RHS, ge, ">=", "<", __VA_ARGS__) | ||
| 281 | #endif | ||
| 282 | |||
| 283 | //====================================================================================================================== | ||
| 284 | /// @} | ||
| 285 | //====================================================================================================================== | ||
| 286 | |||
| 287 | //====================================================================================================================== | ||
| 288 | /** | ||
| 289 | @name Runtime Typed Relation Checks | ||
| 290 | @{ | ||
| 291 | **/ | ||
| 292 | //====================================================================================================================== | ||
| 293 | |||
| 294 | #define TTS_TYPED_RELATION(A, B, OP, T, F, ...) TTS_TYPED_RELATION_##__VA_ARGS__(A, B, OP, T, F) | ||
| 295 | #define TTS_TYPED_RELATION_(A, B, OP, T, F) TTS_TYPED_RELATION_IMPL(A, B, OP, T, F, TTS_FAIL) | ||
| 296 | #define TTS_TYPED_RELATION_REQUIRED(A, B, OP, T, F) \ | ||
| 297 | TTS_TYPED_RELATION_IMPL(A, B, OP, T, F, TTS_FATAL) | ||
| 298 | |||
| 299 | #define TTS_TYPED_RELATION_IMPL(A, B, OP, T, F, FAILURE) \ | ||
| 300 | ::tts::_::check_typed_relation( \ | ||
| 301 | ::tts::_::OP, A, B, TTS_CHECK_SITE(FAILURE, TTS_STRING(A), T, TTS_STRING(B), F)) /**/ | ||
| 302 | |||
| 303 | //====================================================================================================================== | ||
| 304 | /** | ||
| 305 | @def TTS_TYPED_EQUAL | ||
| 306 | @brief Performs type and equality comparison between two expressions | ||
| 307 | |||
| 308 | This test behaves as @ref TTS_EQUAL but also verify that both arguments's types are the same. | ||
| 309 | |||
| 310 | @param LHS, RHS Expressions to compare. | ||
| 311 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 312 | |||
| 313 | @groupheader{Example} | ||
| 314 | @snippet doc/typed_equal.cpp snippet | ||
| 315 | **/ | ||
| 316 | //====================================================================================================================== | ||
| 317 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 318 | #define TTS_TYPED_EQUAL(LHS, RHS, ...) | ||
| 319 | #else | ||
| 320 | #define TTS_TYPED_EQUAL(LHS, RHS, ...) TTS_TYPED_RELATION(LHS, RHS, eq, "==", "!=", __VA_ARGS__) | ||
| 321 | #endif | ||
| 322 | |||
| 323 | //====================================================================================================================== | ||
| 324 | /** | ||
| 325 | @def TTS_TYPED_NOT_EQUAL | ||
| 326 | @brief Performs type and equality comparison between two expressions | ||
| 327 | |||
| 328 | This test behaves as @ref TTS_NOT_EQUAL but also verify that both arguments's types are the same. | ||
| 329 | |||
| 330 | @param LHS, RHS Expressions to compare. | ||
| 331 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 332 | |||
| 333 | @groupheader{Example} | ||
| 334 | @snippet doc/typed_not_equal.cpp snippet | ||
| 335 | **/ | ||
| 336 | //====================================================================================================================== | ||
| 337 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 338 | #define TTS_TYPED_NOT_EQUAL(LHS, RHS, ...) | ||
| 339 | #else | ||
| 340 | #define TTS_TYPED_NOT_EQUAL(LHS, RHS, ...) \ | ||
| 341 | TTS_TYPED_RELATION(LHS, RHS, neq, "!=", "==", __VA_ARGS__) | ||
| 342 | #endif | ||
| 343 | |||
| 344 | //====================================================================================================================== | ||
| 345 | /** | ||
| 346 | @def TTS_TYPED_LESS | ||
| 347 | @brief Performs type and equality comparison between two expressions | ||
| 348 | |||
| 349 | This test behaves as @ref TTS_LESS but also verify that both arguments's types are the same. | ||
| 350 | |||
| 351 | @param LHS, RHS Expressions to compare. | ||
| 352 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 353 | |||
| 354 | @groupheader{Example} | ||
| 355 | @snippet doc/typed_less.cpp snippet | ||
| 356 | **/ | ||
| 357 | //====================================================================================================================== | ||
| 358 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 359 | #define TTS_TYPED_LESS(LHS, RHS, ...) | ||
| 360 | #else | ||
| 361 | #define TTS_TYPED_LESS(LHS, RHS, ...) TTS_TYPED_RELATION(LHS, RHS, lt, "<", ">=", __VA_ARGS__) | ||
| 362 | #endif | ||
| 363 | |||
| 364 | //====================================================================================================================== | ||
| 365 | /** | ||
| 366 | @def TTS_TYPED_GREATER | ||
| 367 | @brief Performs type and equality comparison between two expressions | ||
| 368 | |||
| 369 | This test behaves as @ref TTS_GREATER but also verify that both arguments's types are the same. | ||
| 370 | |||
| 371 | @param LHS, RHS Expressions to compare. | ||
| 372 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 373 | |||
| 374 | @groupheader{Example} | ||
| 375 | @snippet doc/typed_greater.cpp snippet | ||
| 376 | **/ | ||
| 377 | //====================================================================================================================== | ||
| 378 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 379 | #define TTS_TYPED_GREATER(LHS, RHS, ...) | ||
| 380 | #else | ||
| 381 | #define TTS_TYPED_GREATER(LHS, RHS, ...) TTS_TYPED_RELATION(LHS, RHS, gt, ">", "<=", __VA_ARGS__) | ||
| 382 | #endif | ||
| 383 | |||
| 384 | //====================================================================================================================== | ||
| 385 | /** | ||
| 386 | @def TTS_TYPED_LESS_EQUAL | ||
| 387 | @brief Performs type and equality comparison between two expressions | ||
| 388 | |||
| 389 | This test behaves as @ref TTS_LESS_EQUAL but also verify that both arguments's types are the same. | ||
| 390 | |||
| 391 | @param LHS, RHS Expressions to compare. | ||
| 392 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 393 | |||
| 394 | @groupheader{Example} | ||
| 395 | @snippet doc/typed_less_equal.cpp snippet | ||
| 396 | **/ | ||
| 397 | //====================================================================================================================== | ||
| 398 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 399 | #define TTS_TYPED_LESS_EQUAL(LHS, RHS, ...) | ||
| 400 | #else | ||
| 401 | #define TTS_TYPED_LESS_EQUAL(LHS, RHS, ...) TTS_TYPED_RELATION(LHS, RHS, le, "<=", ">", __VA_ARGS__) | ||
| 402 | #endif | ||
| 403 | |||
| 404 | //====================================================================================================================== | ||
| 405 | /** | ||
| 406 | @def TTS_TYPED_GREATER_EQUAL | ||
| 407 | @brief Performs type and equality comparison between two expressions | ||
| 408 | |||
| 409 | This test behaves as @ref TTS_GREATER_EQUAL but also verify that both arguments's types are the | ||
| 410 | same. | ||
| 411 | |||
| 412 | @param LHS, RHS Expressions to compare. | ||
| 413 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 414 | |||
| 415 | @groupheader{Example} | ||
| 416 | @snippet doc/typed_greater_equal.cpp snippet | ||
| 417 | **/ | ||
| 418 | //====================================================================================================================== | ||
| 419 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 420 | #define TTS_TYPED_GREATER_EQUAL(LHS, RHS, ...) | ||
| 421 | #else | ||
| 422 | #define TTS_TYPED_GREATER_EQUAL(LHS, RHS, ...) \ | ||
| 423 | TTS_TYPED_RELATION(LHS, RHS, ge, ">=", "<", __VA_ARGS__) | ||
| 424 | #endif | ||
| 425 | |||
| 426 | //====================================================================================================================== | ||
| 427 | /// @} | ||
| 428 | //====================================================================================================================== | ||
| 429 | |||
| 430 | //====================================================================================================================== | ||
| 431 | /** | ||
| 432 | @name Constexpr Relation Checks | ||
| 433 | @{ | ||
| 434 | **/ | ||
| 435 | //====================================================================================================================== | ||
| 436 | |||
| 437 | #define TTS_CEXPR_RELATION(A, B, OP, T, F, ...) TTS_CEXPR_RELATION_##__VA_ARGS__(A, B, OP, T, F) | ||
| 438 | #define TTS_CEXPR_RELATION_(A, B, OP, T, F) TTS_CEXPR_RELATION_IMPL(A, B, OP, T, F, TTS_FAIL) | ||
| 439 | #define TTS_CEXPR_RELATION_REQUIRED(A, B, OP, T, F) \ | ||
| 440 | TTS_CEXPR_RELATION_IMPL(A, B, OP, T, F, TTS_FATAL) | ||
| 441 | |||
| 442 | #define TTS_CEXPR_RELATION_IMPL(A, B, OP, T, F, FAILURE) \ | ||
| 443 | ::tts::_::check_constant_relation<(::tts::_::OP(A, B))>( \ | ||
| 444 | A, B, TTS_CHECK_SITE(FAILURE, TTS_STRING(A), T, TTS_STRING(B), F)) /**/ | ||
| 445 | |||
| 446 | //====================================================================================================================== | ||
| 447 | /** | ||
| 448 | @def TTS_CONSTEXPR_EQUAL | ||
| 449 | @brief Performs equality comparison between two expressions at compile-time | ||
| 450 | |||
| 451 | This comparison is performed by using the proper `operator==` overload or by a | ||
| 452 | [custom comparison](@ref customize-comparison). | ||
| 453 | |||
| 454 | @param LHS, RHS Expressions to compare. | ||
| 455 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 456 | |||
| 457 | @groupheader{Example} | ||
| 458 | @snippet doc/cexpr_equal.cpp snippet | ||
| 459 | **/ | ||
| 460 | //====================================================================================================================== | ||
| 461 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 462 | #define TTS_CONSTEXPR_EQUAL(LHS, RHS, ...) | ||
| 463 | #else | ||
| 464 | #define TTS_CONSTEXPR_EQUAL(LHS, RHS, ...) TTS_CEXPR_RELATION(LHS, RHS, eq, "==", "!=", __VA_ARGS__) | ||
| 465 | #endif | ||
| 466 | |||
| 467 | //====================================================================================================================== | ||
| 468 | /** | ||
| 469 | @def TTS_CONSTEXPR_NOT_EQUAL | ||
| 470 | @brief Performs inequality comparison between two expressions at compile-time | ||
| 471 | |||
| 472 | This comparison is performed by using the proper `operator==` overload or by a | ||
| 473 | [custom comparison](@ref customize-comparison). | ||
| 474 | |||
| 475 | @param LHS, RHS Expressions to compare. | ||
| 476 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 477 | |||
| 478 | @groupheader{Example} | ||
| 479 | @snippet doc/cexpr_not_equal.cpp snippet | ||
| 480 | **/ | ||
| 481 | //====================================================================================================================== | ||
| 482 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 483 | #define TTS_CONSTEXPR_NOT_EQUAL(LHS, RHS, ...) | ||
| 484 | #else | ||
| 485 | #define TTS_CONSTEXPR_NOT_EQUAL(LHS, RHS, ...) \ | ||
| 486 | TTS_CEXPR_RELATION(LHS, RHS, neq, "!=", "==", __VA_ARGS__) | ||
| 487 | #endif | ||
| 488 | |||
| 489 | //====================================================================================================================== | ||
| 490 | /** | ||
| 491 | @def TTS_CONSTEXPR_LESS | ||
| 492 | @brief Performs less-than comparison between two expressions at compile-time. | ||
| 493 | |||
| 494 | This comparison is performed by using the proper `operator<` overload or by a | ||
| 495 | [custom comparison](@ref customize-comparison). | ||
| 496 | |||
| 497 | @param LHS, RHS Expressions to compare. | ||
| 498 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 499 | |||
| 500 | @groupheader{Example} | ||
| 501 | @snippet doc/cexpr_less.cpp snippet | ||
| 502 | **/ | ||
| 503 | //====================================================================================================================== | ||
| 504 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 505 | #define TTS_CONSTEXPR_LESS(LHS, RHS, ...) | ||
| 506 | #else | ||
| 507 | #define TTS_CONSTEXPR_LESS(LHS, RHS, ...) TTS_CEXPR_RELATION(LHS, RHS, lt, "<", ">=", __VA_ARGS__) | ||
| 508 | #endif | ||
| 509 | |||
| 510 | //====================================================================================================================== | ||
| 511 | /** | ||
| 512 | @def TTS_CONSTEXPR_GREATER | ||
| 513 | @brief Performs greater-than comparison between two expressions at compile-time. | ||
| 514 | |||
| 515 | This comparison is performed by using the proper `operator<` overload or by a | ||
| 516 | [custom comparison](@ref customize-comparison). | ||
| 517 | |||
| 518 | @param LHS, RHS Expressions to compare. | ||
| 519 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 520 | |||
| 521 | @groupheader{Example} | ||
| 522 | @snippet doc/cexpr_greater.cpp snippet | ||
| 523 | **/ | ||
| 524 | //====================================================================================================================== | ||
| 525 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 526 | #define TTS_CONSTEXPR_GREATER(LHS, RHS, ...) | ||
| 527 | #else | ||
| 528 | #define TTS_CONSTEXPR_GREATER(LHS, RHS, ...) \ | ||
| 529 | TTS_CEXPR_RELATION(LHS, RHS, gt, ">", "<=", __VA_ARGS__) | ||
| 530 | #endif | ||
| 531 | //====================================================================================================================== | ||
| 532 | |||
| 533 | /** | ||
| 534 | @def TTS_CONSTEXPR_LESS_EQUAL | ||
| 535 | @brief Performs less-or-equal-than comparison between two expressions at compile-time | ||
| 536 | |||
| 537 | This comparison is performed by using the proper `operator<` overload or by a | ||
| 538 | [custom comparison](@ref customize-comparison). | ||
| 539 | |||
| 540 | @param LHS, RHS Expressions to compare. | ||
| 541 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 542 | |||
| 543 | @groupheader{Example} | ||
| 544 | @snippet doc/cexpr_less_equal.cpp snippet | ||
| 545 | **/ | ||
| 546 | //====================================================================================================================== | ||
| 547 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 548 | #define TTS_CONSTEXPR_LESS_EQUAL(LHS, RHS, ...) | ||
| 549 | #else | ||
| 550 | #define TTS_CONSTEXPR_LESS_EQUAL(LHS, RHS, ...) \ | ||
| 551 | TTS_CEXPR_RELATION(LHS, RHS, le, "<=", ">", __VA_ARGS__) | ||
| 552 | #endif | ||
| 553 | |||
| 554 | //====================================================================================================================== | ||
| 555 | /** | ||
| 556 | @def TTS_CONSTEXPR_GREATER_EQUAL | ||
| 557 | @brief Performs greater-or-equal-than comparison between two expressions at compile-time | ||
| 558 | |||
| 559 | This comparison is performed by using the proper `operator<` overload or by a | ||
| 560 | [custom comparison](@ref customize-comparison). | ||
| 561 | |||
| 562 | @param LHS, RHS Expressions to compare. | ||
| 563 | @param ... Optional tag. If equals to `REQUIRED`, this test will stop the program if it fails. | ||
| 564 | |||
| 565 | @groupheader{Example} | ||
| 566 | @snippet doc/cexpr_greater_equal.cpp snippet | ||
| 567 | **/ | ||
| 568 | //====================================================================================================================== | ||
| 569 | #if defined(TTS_DOXYGEN_INVOKED) | ||
| 570 | #define TTS_CONSTEXPR_GREATER_EQUAL(LHS, RHS, ...) | ||
| 571 | #else | ||
| 572 | #define TTS_CONSTEXPR_GREATER_EQUAL(LHS, RHS, ...) \ | ||
| 573 | TTS_CEXPR_RELATION(LHS, RHS, ge, ">=", "<", __VA_ARGS__) | ||
| 574 | #endif | ||
| 575 | |||
| 576 | //====================================================================================================================== | ||
| 577 | /// @} | ||
| 578 | //====================================================================================================================== | ||
| 579 | |||
| 580 | #define TTS_TYPED_CEXPR_RELATION(A, B, OP, T, F, ...) \ | ||
| 581 | TTS_TYPED_CEXPR_RELATION_##__VA_ARGS__(A, B, OP, T, F) | ||
| 582 | #define TTS_TYPED_CEXPR_RELATION_(A, B, OP, T, F) \ | ||
| 583 | TTS_TYPED_CEXPR_RELATION_IMPL(A, B, OP, T, F, TTS_FAIL) | ||
| 584 | #define TTS_TYPED_CEXPR_RELATION_REQUIRED(A, B, OP, T, F) \ | ||
| 585 | TTS_TYPED_CEXPR_RELATION_IMPL(A, B, OP, T, F, TTS_FATAL) | ||
| 586 | |||
| 587 | #define TTS_TYPED_CEXPR_RELATION_IMPL(A, B, OP, T, F, FAILURE) \ | ||
| 588 | ::tts::_::check_typed_constant_relation<(::tts::_::OP(A, B))>( \ | ||
| 589 | A, B, TTS_CHECK_SITE(FAILURE, TTS_STRING(A), T, TTS_STRING(B), F)) /**/ | ||
| 590 | |||
| 591 | #define TTS_TYPED_CONSTEXPR_EQUAL(LHS, RHS, ...) \ | ||
| 592 | TTS_TYPED_CEXPR_RELATION(LHS, RHS, eq, "==", "!=", __VA_ARGS__) | ||
| 593 | #define TTS_TYPED_CONSTEXPR_NOT_EQUAL(LHS, RHS, ...) \ | ||
| 594 | TTS_TYPED_CEXPR_RELATION(LHS, RHS, neq, "!=", "==", __VA_ARGS__) | ||
| 595 | #define TTS_TYPED_CONSTEXPR_LESS(LHS, RHS, ...) \ | ||
| 596 | TTS_TYPED_CEXPR_RELATION(LHS, RHS, lt, "<", ">=", __VA_ARGS__) | ||
| 597 | #define TTS_TYPED_CONSTEXPR_GREATER(LHS, RHS, ...) \ | ||
| 598 | TTS_TYPED_CEXPR_RELATION(LHS, RHS, gt, ">", "<=", __VA_ARGS__) | ||
| 599 | #define TTS_TYPED_CONSTEXPR_LESS_EQUAL(LHS, RHS, ...) \ | ||
| 600 | TTS_TYPED_CEXPR_RELATION(LHS, RHS, le, "<=", ">", __VA_ARGS__) | ||
| 601 | #define TTS_TYPED_CONSTEXPR_GREATER_EQUAL(LHS, RHS, ...) \ | ||
| 602 | TTS_TYPED_CEXPR_RELATION(LHS, RHS, ge, ">=", "<", __VA_ARGS__) | ||
| 603 | |||
| 604 | //====================================================================================================================== | ||
| 605 | /// @} | ||
| 606 | //====================================================================================================================== | ||
| 607 |