C++ Logo

std-proposals

Advanced search

[std-proposals] Attributes introspection

From: Aurelien Cassagnes <aurelien.cassagnes_at_[hidden]>
Date: Sun, 14 Apr 2024 10:33:16 +0900
Draft for "Attributes introspection"

Attributes are used to great extent and there likely will be attributes
added as the language evolve.
What is missing now is a way for generic code to look into the attributes
related to an entity.
A motivating example is following

#include <functional>

[[nodiscard]] bool foo(int i) { return i % 2 ; }

template <class F, class... Args>
constexpr std::invoke_result_t<F, Args...> logInvoke(F&& f, Args&&... args)
{
// Do some extra work, log the call
// ...
// Fwd call
return std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
}

int main() {
foo(0); // Warning on discarded return
logInvoke(foo, 0); // No warning on discarded return
}

Other examples of wrapping around callables can be found, whether by
closure or explicity registering callbacks for dispatch, etc.
The proposal here is to introduce a `declattr` keyword to look into
attributes bound to an entity, the form would be likely equivalent to how
`decltype` or `declval` are used.

Received on 2024-04-14 01:33:30