Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Those techniques being less annoying is highly debatable ;). Working with void* is annoying, header includes look quite ugly with the ## concatenation everywhere or even a wrapper macro. It also gets much worse when you need to customize the suffix (because type_argument is char* or whatever).

Sometimes the best option is an external script to instantiate a template file.



It may be debatable, but I would say C++'s template syntax is not nicer. I do not think working with void pointers is annoying, but I also prefer the container_of approach. The ## certainly has the limitation that you need to name things first, but I do not think this much of a downside.

BTW, here is some generic code in C using a variadic type. I think this quite nice. https://godbolt.org/z/jxz6Y6f9x

Running a program for meta programming are always a possibility, and I would agree that sometimes the best solution.


I don't think

    T ## _foo (T foo, ...)
is that much different from

    <T>::foo (T foo, ...)
Same for:

    foo (Object * a)
vs:

    foo (void * a)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: