"Generating" Data structures (Day 140)

@Casey

On Day 140, you mention you normally don't hand-roll linked-lists that require arbitrary deletion, but rather "generate them as needed".

Knowing your views on templates, do you roll your own special-sauce metaprogramming technique? If so, could you potentially elaborate?

Sorry if this comes up later in the series, I am behind.
Yes, generally speaking once you have a meta pass in your build, you can just generate whatever you want, so if you want linked lists, you just generate them. It's like templates without the suck :)

- Casey
@Casey

Thanks for getting back to me - I had a feeling this was the case.

That being said, when I think about how I would go about adding a meta pass to generate code, my ideas mostly converge to something that very much resembles C++'s templating system (a consequence, I think, of being raised on templates, making it hard to think outside the box).

Do you mind elaborating/giving any tips on what degrees of freedom you seek to exploit with metaprogramming to give yourself more power/flexibility/control in the code generation?

Thanks
- Zach

Edited by Zachary on
Well really you don't even need to do anything "more" than what C++ attempts to do in order for it to be better than C++. Just the fact that the code comes out plainly readable and can be controlled with more straighforward syntax is more than enough reason to use a metaprogramming approach instead of templates!

- Casey
cmuratori
Well really you don't even need to do anything "more" than what C++ attempts to do in order for it to be better than C++. Just the fact that the code comes out plainly readable and can be controlled with more straighforward syntax is more than enough reason to use a metaprogramming approach instead of templates!

- Casey


One thing I miss when using templates is seeing the templated code after the template parameters are known and inserted and having the error messages point to that code (possibly in a nicer format).

makes me wonder... Do "precompiled" headers also include the instantiated templated (like template specializations) to avoid recompiling them again and again?
@Casey

Thanks for getting back to me. I cheated, skipped ahead, and watched your special stream on implementing introspection with metaprogramming. Very neat stuff - probably should have done that first.

Anyways, thanks again, and look forward to some more episodes in the future - keep up the great work :)

- Zach