r/cpp • u/_bstaletic • Jun 21 '26
Pymetabind: Writing pybind11 bindings with C++26 reflections
https://codeberg.org/bstaletic/pymetabind/
81
Upvotes
r/cpp • u/_bstaletic • Jun 21 '26
View all comments
Show parent comment
1
u/_bstaletic Jun 21 '26 edited Jun 21 '26
I could, but I'm trying to minimize my static memory footprint.
Oh, this can easily happen to you without structured bindings. Here's an example:
If you change
main()to this:...then it compiles. Nothing special about structured bindings. They are just how I have learned about this.
Another place where this showed up in pymetabind is properties, where my structure looks like this:
Now
namebecomes "infected" with being consteval-only and I had to do this silly thing:https://codeberg.org/bstaletic/pymetabind/src/branch/master/include/pymetabind/bind/class.hpp#L140
The name
non_escalating_nameis indicative of what happens. That whole function,bind_classis neitherconstevalnorconstexpr. It can't be, because it callspybind11::class_::def_whatever(). So what happens if a non-constexpr function tries to evaluate a consteval-only expression? The expression is treated as "immediate-escalating" and the function becomes implicitlyconsteval. For a function likebind_class, that makes no sense.The compiler error is super vague and it took me a while to figure out what is making the call to
py::class_::def_propertyan immediate-escalating expression.