WPILibC++ 2023.4.3
drake_assert.h File Reference

Provides Drake's assertion implementation. More...

#include <type_traits>

Go to the source code of this file.

Classes

struct  drake::assert::ConditionTraits< Condition >
 

Namespaces

namespace  drake
 
namespace  drake::internal
 
namespace  drake::assert
 

Macros

#define DRAKE_ASSERT_IS_ARMED
 
#define DRAKE_UNREACHABLE()
 
#define DRAKE_DEMAND(condition)
 
#define DRAKE_ASSERT(condition)   DRAKE_DEMAND(condition)
 
#define DRAKE_ASSERT_VOID(expression)
 

Functions

void drake::internal::Abort (const char *condition, const char *func, const char *file, int line)
 
void drake::internal::AssertionFailed (const char *condition, const char *func, const char *file, int line)
 

Variables

constexpr bool drake::kDrakeAssertIsArmed = true
 
constexpr bool drake::kDrakeAssertIsDisarmed = false
 

Detailed Description

Provides Drake's assertion implementation.

This is intended to be used both within Drake and by other software. Drake's asserts can be armed and disarmed independently from the system-wide asserts.

Macro Definition Documentation

◆ DRAKE_ASSERT

#define DRAKE_ASSERT (   condition)    DRAKE_DEMAND(condition)

◆ DRAKE_ASSERT_IS_ARMED

#define DRAKE_ASSERT_IS_ARMED

◆ DRAKE_ASSERT_VOID

#define DRAKE_ASSERT_VOID (   expression)
Value:
do { \
static_assert( \
std::is_convertible_v<decltype(expression), void>, \
"Expression should be void."); \
expression; \
} while (0)

◆ DRAKE_DEMAND

#define DRAKE_DEMAND (   condition)
Value:
do { \
typedef ::drake::assert::ConditionTraits< \
typename std::remove_cv_t<decltype(condition)>> Trait; \
static_assert(Trait::is_valid, "Condition should be bool-convertible."); \
static_assert( \
!std::is_pointer_v<decltype(condition)>, \
"When using DRAKE_DEMAND on a raw pointer, always write out " \
"DRAKE_DEMAND(foo != nullptr), do not write DRAKE_DEMAND(foo) " \
"and rely on implicit pointer-to-bool conversion."); \
if (!Trait::Evaluate(condition)) { \
#condition, __func__, __FILE__, __LINE__); \
} \
} while (0)
void AssertionFailed(const char *condition, const char *func, const char *file, int line)

◆ DRAKE_UNREACHABLE

#define DRAKE_UNREACHABLE ( )
Value:
"Unreachable code was reached?!", __func__, __FILE__, __LINE__)
void Abort(const char *condition, const char *func, const char *file, int line)