Skip to content
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

Any methods to make attribute declarable in C++ as well? #89

Open
roxk opened this issue Jun 30, 2023 · 1 comment
Open

Any methods to make attribute declarable in C++ as well? #89

roxk opened this issue Jun 30, 2023 · 1 comment

Comments

@roxk
Copy link
Owner

roxk commented Jun 30, 2023

Right now the only (popular) feature of midl that requires non-trivial annotation is attribute. Commonly used attribute include:

  1. Windows repo's contract
  2. Xaml content
  3. bindable

Is it possible to declare these in C++ as well without needing to write [[idlgen::attribute("bindable",)]]? Note that C++ attribute is not extensible.


Idea

struct based

namespace idlgen
{
template <char const* Property = nullptr>
struct attribute
{
};
}

namespace wux
{
struct bindable_attribute : idlgen::attribute<>
{
};
template<char const* Property>
struct content_property_attribute : idlgen::attribute<Property>
{
};
}

const char property_name[] = "Property";
struct ViewModel : ViewModelT<ViewModel>, bindable_attribute, content_property_attribute<property_name>
{
}

SO says it's possible to use const char* as template parameter. Since we need to support C++17 C++20's std::string-in-template-parameter is not something idlgen can enjoy yet.

@roxk
Copy link
Owner Author

roxk commented Jun 30, 2023

It works, but property_name must be defined outside of the class which can leak impl detail/introduce pollution (C++17 doesn't support module yet). Everything "just works" in C++20 though...

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

No branches or pull requests

1 participant