Handmade Network»Forums
Jack Mott
110 posts
Web Developer by day, game hobbyist by night.
For those that don't like to use C++ templates, what do you do instead?
Do you just use some sort of void pointer approach?

Do you use macros to approximate templates (I see this in the stb libs)? Do this not have similar compile time implications?

Do you just write however many versions of the function you need for each type?

Do you not like templates in principle, or simply not like how they work in C++, and is that because of compile times alone, or other reasons?
498 posts
For those that don't like to use C++ templates, what do you do instead?
There is no real need to use templates (or something meta programming) at all.

If I'd need to use something classic template (like containers) while boycotting them I'd either go for a void*+per-element-size or manually expand the "template". Casting pointers is a no-op anyway.
Daniel Hesslow
7 posts
For those that don't like to use C++ templates, what do you do instead?
Edited by Daniel Hesslow on
I currently have macros for defining the data structure for each type ie.

#define DEFINE_DynamicArray(type)\
{\
size_t len;\
size_t capacity;\
type *start;\
}
...

Mayor downside being that you can't step into it in vs and that you can't include guard it..
Thinking about moving it out into another file to solve the first problem which would make the usage:

#define type int
#include "dynamic_array.c"
#undef type

since I'm only a student and working on this kinda stuff myself multiple includes aren't really a problem but I assume it wouldn't work too well on a bigger project.
Jack Mott
110 posts
Web Developer by day, game hobbyist by night.
For those that don't like to use C++ templates, what do you do instead?
Thanks, it is an interesting reply. I agree there is no need, but it *is* convenient at times. I wonder if languages where templates are implemented better, and don't cause compile time issues lead people to be more productive, or if easy access to templates lead us to make things overly complicated.

I know we toss them around constantly in our C# web code for collections and it would certainly be cumbersome to have to deal with those by hand.