C++ Logo

sg7

Advanced search

Re: Request for supporting and enumerating user-defined attributes

From: Wyatt Childers <wcc_at_[hidden]>
Date: Mon, 16 Oct 2023 13:26:08 -0400
I agree this is a very important use case. I wish attributes were not
ignorable, the Clang implementer veto here is actually quite
frustrating. I think Java actually got this one right with their
annotations (ref:
https://docs.oracle.com/javase/1.5.0/docs/guide/language/annotations.html).

> struct serializable
> {
> bool value;
> };
>
> struct Foo
> {
> @serializable(true)
> int data;
> };
That said, I like this syntax, I think it improves upon the Java syntax
and would work very well for C++.

My major concern is that this will just end up subsuming attributes
anyways with folks writing things like:

    @deprecated() [[deprecated]] struct foo {};

Perhaps to avoid that, there are (at least for attributes that folks
might want to reflect) corresponding "standard annotations" that are
/implied/ by using the attribute (if the attribute is not "being ignored").

e.g.,

    [[deprecated]] struct foo {};
    /* implies */
    @std::deprecated() struct foo {};

Uses of the annotation directly would be not be ignorable.

- Wyatt

On 10/16/23 06:24, Peter Dimov via SG7 wrote:
> Jeremy Ong wrote:
>> Thinking outloud, as an example, we might declare:
>>
>> template <bool>
>> class Serializable {};
>>
>> And later use this class as a decorator like so:
>>
>> struct Foo
>> {
>> @Serializable<true>
>> int data;
>> }:
> We can do this, but it isn't necessary. @type is not
> substantially easier to implement than @expr, so we
> can just do
>
> struct serializable
> {
> bool value;
> };
>
> struct Foo
> {
> @serializable(true)
> int data;
> };
>
> instead.
>
>

Received on 2023-10-16 17:26:12