NeFut Logo NeFut
Admin Login

[C++ Magic] C++26: New Features for Function Location and Reflection

Published at: 2026-06-10 09:00 Last updated: 2026-06-11 02:35
#algorithm #optimization #C++

C++26 introduces new special functions that, when used as default arguments, allow querying the call location, similar to std::source_location::current(). By using one of these functions, for example, std::meta::current_function, caller function reflection can be acquired and inspected. This enables basic function coloring via function parameters and annotations. While I don't see immediate practical uses, I think it's cool and wanted to share this proof of concept.

#include <iostream>
#include <source_location>

void example_function(const std::source_location location = std::source_location::current()) {
    std::cout << "Called from: " << location.file_name() << " at line " << location.line() << '\n';
}

int main() {
    example_function(); // Outputs the call location
    return 0;
}

Blogger's Review: The new features in C++26 provide powerful support for function reflection and call location querying, enhancing debugging convenience and laying the groundwork for future code analysis tools. Although the current practical applications seem limited, its potential is worth noting.

Original Source: https://www.reddit.com/r/cpp/comments/1u1eca5/we_have_colored_functions_at_home/

[h] Back to Home