IRSOL
C++ code implementing socket server for interacting with Baumer camera.
macros.hpp File Reference

Common portability and diagnostic macros for the irsol library. More...

#include "irsol/assert.hpp"
#include "irsol/traits.hpp"

Go to the source code of this file.

Macros

#define IRSOL_MAYBE_UNUSED
 Suppresses compiler warnings about unused variables or parameters.
 
#define IRSOL_SUPPRESS_UNUSED_STRUCTURED_BINDING_START
 Begins a diagnostic suppression block for unused structured binding variables.
 
#define IRSOL_SUPPRESS_UNUSED_STRUCTURED_BINDING_END
 Ends a diagnostic suppression block started with IRSOL_SUPPRESS_UNUSED_STRUCTURED_BINDING_START.
 
#define _IRSOL_UNREACHABLE_IMPL()
 Internal macro for compiler-specific unreachable code markers.
 
#define IRSOL_UNREACHABLE()   _IRSOL_UNREACHABLE_IMPL()
 Indicates unreachable code to the compiler.
 
#define IRSOL_STATIC_UNREACHABLE(messageLiteral)
 Marks unreachable branches in constexpr functions.
 
#define _IRSOL_STATIC_ASSERT_MISSING_TEMPLATE_SPECIALIZATION(T, messageLiteral)    IRSOL_STATIC_ASSERT((irsol::traits::always_false<T>::value), messageLiteral)
 Internal helper to trigger a static assertion when a required template specialization is missing.
 
#define IRSOL_MISSING_TEMPLATE_SPECIALIZATION(T, funcNameLiteral)
 Emits a compile-time error when no template specialization is available.
 

Detailed Description

Common portability and diagnostic macros for the irsol library.

Provides cross-platform macros to suppress unused variable warnings, indicate unreachable code paths, and enforce template specialization requirements.

These utilities help ensure code clarity and maintainability across compilers and standard versions, and are typically used in template metaprogramming, constexpr logic, or when interfacing with platform-specific APIs.

Definition in file macros.hpp.

Macro Definition Documentation

◆ _IRSOL_STATIC_ASSERT_MISSING_TEMPLATE_SPECIALIZATION

#define _IRSOL_STATIC_ASSERT_MISSING_TEMPLATE_SPECIALIZATION (   T,
  messageLiteral 
)     IRSOL_STATIC_ASSERT((irsol::traits::always_false<T>::value), messageLiteral)

Internal helper to trigger a static assertion when a required template specialization is missing.

This macro should not be used directly. Use IRSOL_MISSING_TEMPLATE_SPECIALIZATION instead.

Parameters
TThe template type parameter for which specialization is missing.
messageLiteralA description of the missing specialization.

Definition at line 148 of file macros.hpp.

◆ _IRSOL_UNREACHABLE_IMPL

#define _IRSOL_UNREACHABLE_IMPL ( )
Value:
do { \
} while(0)

Internal macro for compiler-specific unreachable code markers.

Expands to a compiler intrinsic that informs the optimizer the code is unreachable. Do not use directly—use IRSOL_UNREACHABLE instead.

Definition at line 84 of file macros.hpp.

85 { \
86 } while(0)

◆ IRSOL_MAYBE_UNUSED

#define IRSOL_MAYBE_UNUSED

Suppresses compiler warnings about unused variables or parameters.

Use this macro to annotate variables or function parameters that are intentionally unused. It adapts to the best syntax supported by the current compiler and language standard.

IRSOL_MAYBE_UNUSED int unusedVar;
void f(IRSOL_MAYBE_UNUSED int unusedParam) {
// do nothing
}
#define IRSOL_MAYBE_UNUSED
Suppresses compiler warnings about unused variables or parameters.
Definition macros.hpp:39

Definition at line 39 of file macros.hpp.

◆ IRSOL_MISSING_TEMPLATE_SPECIALIZATION

#define IRSOL_MISSING_TEMPLATE_SPECIALIZATION (   T,
  funcNameLiteral 
)
Value:
T, \
"Function '" funcNameLiteral "' lacks a template specialization for this type. " \
"Please ensure you handle all required template types explicitly.")
#define _IRSOL_STATIC_ASSERT_MISSING_TEMPLATE_SPECIALIZATION(T, messageLiteral)
Internal helper to trigger a static assertion when a required template specialization is missing.
Definition macros.hpp:148

Emits a compile-time error when no template specialization is available.

This macro is useful in if constexpr chains to clearly indicate that a required template specialization has not been provided.

template <typename T>
void process() {
if constexpr (std::is_integral_v<T>) {
// Implementation for integral types
} else {
}
}
#define IRSOL_MISSING_TEMPLATE_SPECIALIZATION(T, funcNameLiteral)
Emits a compile-time error when no template specialization is available.
Definition macros.hpp:173
Parameters
TThe template type parameter.
funcNameLiteralA string literal representing the function or context.

Definition at line 173 of file macros.hpp.

◆ IRSOL_STATIC_UNREACHABLE

#define IRSOL_STATIC_UNREACHABLE (   messageLiteral)
Value:
"Unreachable constexpr code triggered: " messageLiteral); \
_IRSOL_UNREACHABLE_IMPL()
#define IRSOL_STATIC_ASSERT
Compile-time static assertion macro.
Definition assert.hpp:138
Always evaluates to false, regardless of the type.
Definition traits.hpp:54

Marks unreachable branches in constexpr functions.

This macro emits a compile-time error when reached. It is designed for use in if constexpr branches that should never be selected at compile-time.

constexpr int safeDivide(int x) {
if constexpr (x == 0) {
IRSOL_STATIC_UNREACHABLE("Division by zero");
}
return 10 / x;
}
#define IRSOL_STATIC_UNREACHABLE(messageLiteral)
Marks unreachable branches in constexpr functions.
Definition macros.hpp:130
Note
If this macro is reached in runtime code (i.e., not constexpr), it still falls back to IRSOL_UNREACHABLE to mark the code as unreachable at runtime.
Parameters
messageLiteralA literal C-string message describing the unreachable condition.

Definition at line 130 of file macros.hpp.

133 : " messageLiteral); \
134 _IRSOL_UNREACHABLE_IMPL()

◆ IRSOL_SUPPRESS_UNUSED_STRUCTURED_BINDING_END

#define IRSOL_SUPPRESS_UNUSED_STRUCTURED_BINDING_END

Ends a diagnostic suppression block started with IRSOL_SUPPRESS_UNUSED_STRUCTURED_BINDING_START.

Definition at line 69 of file macros.hpp.

◆ IRSOL_SUPPRESS_UNUSED_STRUCTURED_BINDING_START

#define IRSOL_SUPPRESS_UNUSED_STRUCTURED_BINDING_START

Begins a diagnostic suppression block for unused structured binding variables.

Useful when only part of a structured binding is used inside a loop or block.

for (auto& [key, value] : map) {
doSomethingWith(key);
}
#define IRSOL_SUPPRESS_UNUSED_STRUCTURED_BINDING_START
Begins a diagnostic suppression block for unused structured binding variables.
Definition macros.hpp:68
#define IRSOL_SUPPRESS_UNUSED_STRUCTURED_BINDING_END
Ends a diagnostic suppression block started with IRSOL_SUPPRESS_UNUSED_STRUCTURED_BINDING_START.
Definition macros.hpp:69
auto value

Definition at line 68 of file macros.hpp.

◆ IRSOL_UNREACHABLE

#define IRSOL_UNREACHABLE ( )    _IRSOL_UNREACHABLE_IMPL()

Indicates unreachable code to the compiler.

Use this macro in logically unreachable branches (e.g., fully covered switch cases) to suppress warnings and help with optimization.

int getCode(Type t) {
switch (t) {
case Type::A: return 1;
case Type::B: return 2;
}
}
#define IRSOL_UNREACHABLE()
Indicates unreachable code to the compiler.
Definition macros.hpp:107
Warning
If the control flow does reach this macro, undefined behavior may occur.

Definition at line 107 of file macros.hpp.