3 ms·
I think the difference is that you can't (afaik) generate a struct with metaprogramming.
by tines 11y ago
I think the difference is that you can't (afaik) generate a struct with metaprogramming.
- jlarocco 11y agoBut you can generate them with macros. The Boost preprocessor library can help a lot. At work we use kind of a hybrid approach. We have generator macros that spit out named tuple classes that use a bunch of magic and template meta-programming. It should go without saying that the macro implementation is ugly and only a few people understand it very well, but we don't have to change them much any more, and the resulting named tuples are easy to use and generally work exactly as expected.
- cbsmith 11y agoYes, lots of people do named tuples with preprocessor logic of one kind or another (protoc and a variety of serialization libraries basically give this to you). It's much cleaner if you can use the type system to do the job for you.
- marshray 11y agoIt's been a while since I even considered doing something like this, but you could probably generate them by recursively inheriting from a chain of generated base classes. That said, most everyone who's looked at the problem has ended up going with macros instead. :-)
- tines 11y agoI'm not sure you could do what this does and give the members of the struct a user-supplied name though.