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