FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
/flatimage/src/macro.hpp

Conditionally return from function with optional logging.

Conditionally return from function with optional loggingEvaluates a condition and if true, optionally logs a message and returns the specified value. For void functions, use 'void' as the return value.

Parameters
conditionThe condition to evaluate
valueThe value to return (use ',,' for void functions)
...Optional format string and arguments for logging
// Void function with logging
return_if(ptr == nullptr,,"E::Null pointer encountered");
// Return with value and logging
return_if(error_code != 0, -1, "E::Operation failed with code {}", error_code);
// Return without logging
return_if(done, result);
#pragma once
#include "lib/log.hpp"
#define return_if(condition, value, ...) \
if (condition) { \
__VA_OPT__(logger(__VA_ARGS__);) \
return value; \
}
#define break_if(condition, ...) \
if (condition) { \
__VA_OPT__(logger(__VA_ARGS__);) \
break; \
}
#define continue_if(condition, ...) \
if (condition) { \
__VA_OPT__(logger(__VA_ARGS__);) \
continue; \
}
#define log_if(condition, ...) \
if (condition) { \
logger(__VA_ARGS__); \
}
/* vim: set expandtab fdm=marker ts=2 sw=2 tw=100 et :*/
A library for file logging.