Skip to content

To use custom annotation it requires the type to be equality_comparable #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: p2996
Choose a base branch
from

Conversation

bruce-webb
Copy link

*Issue number of the reported bug or feature request: p3394 usage

Describe your changes
When using a custom annotations and getting access to it with the function annotation_of_type the T is required to be equality_comparable.

If not the compile error message leads down to missing operator != for the type

Testing performed
When testing with new annotations types clangd reports that T doesn't meet the requires clauses. The compile message is also cleaner as well.

namespace lua {
struct rename {
  const char *name;
  
  auto operator<=>(const rename &) const = default;
};

struct Person
{
  [[=lua::rename("firstName")]] std::string first_name;
};

template<typename T>
consteval auto GetName() -> std::string_view {
    return
        std::meta::annotation_of_type<lua::rename>(^^T)
            .transform([](lua::rename rename) {
              return std::string_view(rename.name);
            })
            .value_or(std::meta::display_string_of(^^T));
}

@katzdm katzdm force-pushed the p2996 branch 2 times, most recently from 3cc9fcd to 4ffd254 Compare April 11, 2025 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants