inline-if.hpp 567 B

123456789101112
  1. #pragma once
  2. #warning "these defines break if statements with multiple parameters to templates"
  3. #define if1(statement) if(statement)
  4. #define if2(condition, false) ([&](auto&& value) -> decltype(condition) { \
  5. return (bool)value ? value : (decltype(condition))false; \
  6. })(condition)
  7. #define if3(condition, true, false) ((condition) ? (true) : (decltype(true))(false))
  8. #define if4(type, condition, true, false) ((condition) ? (type)(true) : (type)(false))
  9. #define if_(_1, _2, _3, _4, name, ...) name
  10. #define if(...) if_(__VA_ARGS__, if4, if3, if2, if1)(__VA_ARGS__)