#pragma once #include #define JVALIDATE_CONCAT2(A, B) A##B #define JVALIDATE_CONCAT(A, B) JVALIDATE_CONCAT2(A, B) #define JVALIDATE_IIF0(IF, ELSE) ELSE #define JVALIDATE_IIF1(IF, ELSE) IF #define JVALIDATE_IIF(CONDITIONAL, IF, ELSE) JVALIDATE_CONCAT(JVALIDATE_IIF, CONDITIONAL)(IF, ELSE) /** * @brief Assert a certain pre/post-condition is true, else return the default * expression (or void). * * @param condition A boolean or boolean-like expression that should be TRUE. * If the condition is FALSE, then the other params are used to produce errors. * * @param ... Zero or One arguments representing the return value if the * condition is FALSE. Zero arguments is equivalent to `return void();`, which * doesn't need to be explicitly stated. */ #define JVALIDATE_RETURN_UNLESS(condition, ...) \ if (!(condition)) [[unlikely]] { \ return __VA_ARGS__; \ } /** * @brief Assert a certain pre/post-condition is false, else return the default * expression (or void). * * @param condition A boolean or boolean-like expression that should be FALSE. * If the condition is TRUE, then the other params are used to produce errors. * * @param ... Zero or One arguments representing the return value if the * condition is TRUE. Zero arguments is equivalent to `return void();`, which * doesn't need to be explicitly stated. */ #define JVALIDATE_RETURN_IF(condition, ...) \ if (condition) [[unlikely]] { \ return __VA_ARGS__; \ }