I find reflection on attributes somewhat problematic, because attributes have arguments
- Any solution to reflect on attributes should consider the arguments
- Any general solution to reflect on attributes should work in the general case, not just for standard attributes.
- In the general case, arguments cannot be reflected because they are token soup with complete disregard for C++ grammar.
There is also the impact on the whole attribute ignorability imbroglio.
This leaves a few options for standard attributes:
- Make it an opaque thing that you can copy but not inspect. This is close to what you propose, but the discussion about what happens to arguments should still be present.
I wonder if something like [[nodiscard_if(std::meta::is_nodiscard(some_reflection))]] isn't sufficient for your use case.
Given the limited number of standard attributes, I think it would be fine to have individual queries for them, and there arguments (std::meta::nodiscard_reason)
- Find a way for existing attributes to correspond to a strongly typed object that can then be queried for arguments etc
- Introduce a completely different mechanism akin to decorators in other languages. This is useful but I haven't figured a way to make existing attributes work with that.