Repository navigation
Attribute
Tsukini edited this page Oct 4, 2026
·
1 revision
Note
Section _Attribute (in _Utils) · Macros (no namespace) · Headers utils/attribute/
Short macros for the compiler attributes, defined from the C++ version used (c++20.hpp, c++17.hpp, c++14.hpp, fallback.hpp): an attribute not supported by the version becomes empty, so the code stays the same everywhere.
| Macro | Attribute |
|---|---|
_nodiscard |
[[nodiscard]] |
_noreturn |
[[noreturn]] (on the first declaration) |
_noinline |
[[noinline]] |
_unused |
[[maybe_unused]] |
_fallthrough |
[[fallthrough]] |
_hot / _cold
|
[[gnu::hot]] / [[gnu::cold]]
|
_hidden |
[[gnu::visibility("hidden")]] |
_ctor / _dtor
|
[[gnu::constructor]] / [[gnu::destructor]] (run before / after main) |
| Macro | Usage |
|---|---|
_likely / _unlikely
|
[[likely]] / [[unlikely]], after the condition: if (error) _unlikely {...}
|
_likely_c(c) / _unlikely_c(c)
|
__builtin_expect inside an expression |
_expect(c, v) |
__builtin_expect(c, v) |
_assume(expr) |
[[assume(expr)]] |
| Macro | Attribute |
|---|---|
_alignas(n) |
alignas(n) (ex: _alignas(std::hardware_destructive_interference_size), defined to 64 when the library doesn't provide it) |
_packed |
[[gnu::packed]] |
_noaddress |
[[no_unique_address]] |
_nonnull(i) |
[[gnu::nonnull(i)]] |
_alloc_size(i) / _alloc_size_mul(i, j)
|
[[gnu::alloc_size(...)]] |
_read_only(ptr, size) / _write_only(ptr, size)
|
[[gnu::access(...)]] |
| Macro | Description |
|---|---|
_deprecated(info) |
[[deprecated(info)]] |
_migration(major, minor, fix) |
Renamed API kept until the given version (~vX.Y.Z in the warning) |
_legacy |
Kept for backward compatibility, no removal planned |
The deprecation warnings follow the warning defines (_Warning / _NoWarning).
#define _Attribute
#include <utils/utils.hpp>
_hot _nodiscard int parse(const char* s)
{
if (!s) _unlikely {return -1;}
return 0;
}
_migration(4, 0, 0) inline int oldParse(const char* s) {return parse(s);}Home · Installing · Usage · Tools Preview · Sections · Workflow (CI-CD)
libutils is licensed under MIT (the synced algorithms under CC BY-NC-SA 4.0).