libyggdrasil  v1.0.0
utils.hpp File Reference

Commonly used helper functions. More...

#include <cpp/common/attributes.hpp>
#include <cstring>
#include <type_traits>
#include <utility>
Include dependency graph for utils.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  bsp::dependent_false< T >
 Helper type trait for using static_asserts that should always trigger an error when evaluated. More...
 
class  bsp::scope_guard::ScopeGuardImpl< F >
 Scope Guard implementation. More...
 
struct  bsp::ByteSwapped< T >
 Helper class to store the data of a given type in reverse order. More...
 

Namespaces

 bsp
 
 bsp::scope_guard
 

Macros

#define TOKEN_CONCAT_IMPL(x, y)   x ## y
 
#define TOKEN_CONCAT(x, y)   TOKEN_CONCAT_IMPL(x, y)
 
#define ANONYMOUS_VARIABLE(prefix)   TOKEN_CONCAT(prefix, __COUNTER__)
 
#define SCOPE_GUARD   ::bsp::scope_guard::ScopeGuardOnExit() + [&]()
 Scope Guard for executing code when exiting the current scope with the ability to release it. More...
 
#define ON_SCOPE_EXIT   auto ANONYMOUS_VARIABLE(SCOPE_EXIT_) = SCOPE_GUARD
 Scope Guard for always executing code when exiting the current scope. More...
 

Enumerations

enum  bsp::scope_guard::ScopeGuardOnExit
 

Functions

template<typename F >
constexpr ScopeGuardImpl< F > bsp::scope_guard::operator+ (ScopeGuardOnExit, F &&f)
 
template<typename To , typename From >
To bsp::bit_cast (const From &src) noexcept
 std::bit_cast implementation for doing reinterpret_cast-style conversion without invoking undefined behaviour More...
 
template<typename T >
constexpr T bsp::byteSwap (T value)
 Swaps bytes of input value to convert between big and little endian. More...
 
template<typename T >
auto bsp::enumValue (T value)
 Casts a scoped enum type into its underlying value. More...
 
ALWAYS_INLINE void bsp::doNotOptimize (const auto &value)
 Confuses the compiler to prevent it from optimizing out a variable. Helpful for debugging. More...
 

Variables

template<typename T >
constexpr auto bsp::dependent_false_v = dependent_false<T>::value
 

Detailed Description

Commonly used helper functions.

Author
Fabian Weber, Nikolaij Saegesser

Macro Definition Documentation

◆ ANONYMOUS_VARIABLE

#define ANONYMOUS_VARIABLE (   prefix)    TOKEN_CONCAT(prefix, __COUNTER__)

◆ ON_SCOPE_EXIT

#define ON_SCOPE_EXIT   auto ANONYMOUS_VARIABLE(SCOPE_EXIT_) = SCOPE_GUARD

Scope Guard for always executing code when exiting the current scope.

Example use: ON_SCOPE_EXIT { doCleanup(); };

◆ SCOPE_GUARD

#define SCOPE_GUARD   ::bsp::scope_guard::ScopeGuardOnExit() + [&]()

Scope Guard for executing code when exiting the current scope with the ability to release it.

Example use: auto cleanup = SCOPE_GUARD { doCleanup(); };

◆ TOKEN_CONCAT

#define TOKEN_CONCAT (   x,
 
)    TOKEN_CONCAT_IMPL(x, y)

◆ TOKEN_CONCAT_IMPL

#define TOKEN_CONCAT_IMPL (   x,
 
)    x ## y