reflection.h File
C++ header file with declarations for the µTest++ reflection utilities. More...
Included Headers
Namespaces Index
| namespace | micro_os_plus |
|
The primary namespace for the µOS++ framework. More... | |
| namespace | micro_test_plus |
|
Primary namespace for the µTest++ testing framework. More... | |
| namespace | reflection |
|
Reflection utilities for the µTest++ testing framework. More... | |
Classes Index
| class | source_location |
|
Local implementation of source location information for diagnostics. More... | |
Functions Index
template <class T> | |
| constexpr std::string_view | type_name (void) |
|
Extracts the type name from the __PRETTY_FUNCTION__ identifier. More... | |
Description
C++ header file with declarations for the µTest++ reflection utilities.
This header provides the declarations for the reflection utilities used within the µTest++ framework. It defines interfaces for obtaining source location information and extracting type names at compile time, for the reports of the checks.
The reflection utilities include a local implementation of source_location for standard libraries that do not yet provide std::source_location, and a function to extract concise type names using the compiler-specific __PRETTY_FUNCTION__ identifier. These facilities enable precise identification of code locations and types in test reports.
All definitions reside within the micro_os_plus::micro_test_plus::reflection namespace.
This file is included by micro-os-plus/micro-test-plus.h, which is the header that the applications include.
Functions
type_name()
| nodiscard constexpr |
Extracts the type name from the __PRETTY_FUNCTION__ identifier.
This function template parses the compiler-specific __PRETTY_FUNCTION__ identifier to extract a concise type name for the template parameter T.
Rather than relying on fixed character offsets (which are fragile across compiler versions and namespace changes), the implementation searches for the marker that introduces the template argument in the function signature string:
- Clang formats the signature as "... [T = <typename>]", so the type name lies between the first "[T = " and the last ']'. The marker is searched for as a whole, since the type name may itself contain brackets (e.g. int[3]).
- GCC formats the signature as "... [with T = <typename>]" or, on some versions, "... [with T = <typename>; ...]", so the type name starts after the first "[with T = " and ends at the following ';' or, if there is none, at the last ']'.
If the marker is not found, or the compiler is not supported (e.g. MSVC, which uses __FUNCSIG__ instead of __PRETTY_FUNCTION__), the function returns "unknown" rather than failing to compile, since the name is used only to improve the test output.
The expected layouts are verified at compile time by the static_assert checks that follow the definition.
The name is spelled as the compiler prints it, and is used to identify the expected exception type in the throws<E> failure messages. Only clang and GCC are supported; with other compilers the function returns "unknown".
- Template Parameters
-
T The type whose name is to be extracted.
- Parameters
None.
- Returns
A std::string_view containing the extracted type name, or "unknown" if it cannot be determined.
Definition at line 149 of file reflection-inlines.h.
Reference micro_os_plus::micro_test_plus::reflection::type_name.
Referenced by micro_os_plus::micro_test_plus::detail::expression_formatter::operator<< and micro_os_plus::micro_test_plus::reflection::type_name.
File Listing
The file content with the documentation metadata removed is:
Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.