Thanks for the suggestion, let me take a good look at callbacks.
Another thing that I can't make work elegantly is compiling template functions from C++, since we have no clue to guess which types will be instantiated in the Python code (and they can even depend on user input, so only determined at runtime)
> The Docker image includes clang-p2996, Bloomberg’s experimental Clang fork that implements the reflection proposal. As P2996 moves toward standardization, expect this to land in mainline compilers.
Possible to use that C++26 compiler just to do code generation for the binding code, and then use any other compiler for your actual build? I suppose alternatively could use a parser. Is the reflection code easy to work with in comparison? A year or two ago I spent some hours pulling my hair out trying to do some reflection in C++ until I gave up and spent the 20mins needed to write a python script to read my source files and do the code generation I needed.
The P2996 definitely provides a way to work with reflection, the syntax can be a bit weird at first, but it gets more and more familiar. They have some cool examples here (https://isocpp.org/files/papers/P2996R13.html)
This idea of using C++26 compiler just for codegen sounds interesting. Will definitely give it some thought, thanks for the suggestion (:
I feel a little bit nerd sniped - halfway through the article I wanted to cry out "but the loop!" and then they moved the loop. Nice job, I'm super excited to use this in my own code. I have a bunch of handwritten metadata about C++ classes that I'd rather ditch and use something that the language provides.
This looks very exciting. I have a NodeJS binding I've been contemplating using SWIG. This appears to be much more straight forward. Looking forward to trying it out.
I've added a prebuilt image, so it should be straightforward to try it out. If you have any problems with working on that prebuilt image please open an issue or reach out to me!
> Before P2996, generating Python bindings required either:
I'm missing nanobind here.
> Method lookup. Python sees a.dot and searches for the dot attribute. It checks a.__dict__,
> Each attribute access (self.x) involves:
Since C++ classes are fixed, I'd expect attributes to be declared once in python (slots).One thing yet important for cross-language projects: callbacks (events). Would be nice if the sample could be extended.
Thanks for the suggestion, let me take a good look at callbacks.
Another thing that I can't make work elegantly is compiling template functions from C++, since we have no clue to guess which types will be instantiated in the Python code (and they can even depend on user input, so only determined at runtime)
Cool to see C++ reflection getting somewhere.
> The Docker image includes clang-p2996, Bloomberg’s experimental Clang fork that implements the reflection proposal. As P2996 moves toward standardization, expect this to land in mainline compilers.
Possible to use that C++26 compiler just to do code generation for the binding code, and then use any other compiler for your actual build? I suppose alternatively could use a parser. Is the reflection code easy to work with in comparison? A year or two ago I spent some hours pulling my hair out trying to do some reflection in C++ until I gave up and spent the 20mins needed to write a python script to read my source files and do the code generation I needed.
Btw, it seems that the reflection implementations are progressing quite fast. There is already a gcc version with reflection support that is available on compiler explorer: https://www.reddit.com/r/cpp/comments/1ojbv1a/gcc_implementa...
Will add support for it as soon as I have some time to spare!
The P2996 definitely provides a way to work with reflection, the syntax can be a bit weird at first, but it gets more and more familiar. They have some cool examples here (https://isocpp.org/files/papers/P2996R13.html)
This idea of using C++26 compiler just for codegen sounds interesting. Will definitely give it some thought, thanks for the suggestion (:
I feel a little bit nerd sniped - halfway through the article I wanted to cry out "but the loop!" and then they moved the loop. Nice job, I'm super excited to use this in my own code. I have a bunch of handwritten metadata about C++ classes that I'd rather ditch and use something that the language provides.
If you want, give it a shot with the prebuilt image and let me know if it works for you.
I want to make this project as mature as possible for when support arrives at the upstream version of clang, gcc and msvc. Feedback is appreciated!
This looks very exciting. I have a NodeJS binding I've been contemplating using SWIG. This appears to be much more straight forward. Looking forward to trying it out.
I've added a prebuilt image, so it should be straightforward to try it out. If you have any problems with working on that prebuilt image please open an issue or reach out to me!