Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
static-tests/include/debug.hpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
23 lines (20 sloc)
921 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compilation error must be generated in order to print anything. | |
// This function generates this error (static assertion always fails). | |
// Template parameters of calls containing failed static assertions | |
// are never printed by gcc compiler. | |
template <class val_t> | |
constexpr val_t staticAssertFail(val_t value) { | |
// Value must be passed to trick the compiler | |
// that it's needed to evaluate the assertion. | |
static_assert(value && false, "debugging value"); | |
return value; | |
} | |
// Another function that calls the function above. | |
// Template parameters of this function will be printed by the compiler. | |
template <class val_t, val_t value> | |
constexpr val_t debugStaticValue() { | |
return staticAssertFail(value); | |
} | |
// Helper macro that will be used to print values. | |
// To use it, just wrap a value you wish to debug. | |
#define DSV(v) debugStaticValue<std::remove_cv<std::remove_reference<decltype(v)>::type>::type, v>() | |