_generics #3
Replies: 4 comments
-
Excellent idea; what you are looking for can be accomplished with:
Once you have all your containers registered you may use it as follows
Since generics require knowing the container types up front, it will be up to the programmer to implement generics as they like. |
Beta Was this translation helpful? Give feedback.
-
I am in the process of writing a wiki, and I am going to add this idea to it; thanks for the great tip! |
Beta Was this translation helpful? Give feedback.
-
Fascinating discussion! 💯 It would be the ultimate user-friendly interface to simply have a generic "push_back(container, value)" interface automatically defined for all containers and T that one want to use. Actually, couldn't it be possible in theory to compile-time build the required "list" that must be given to _Generic using advanced macro trickery? After all, the C preprocessor is Turing complete. Or am I just dreaming? :) |
Beta Was this translation helpful? Give feedback.
-
Yes, you may be thinking of the X-Macro: https://en.wikipedia.org/wiki/X_Macro. Combine this with _Generic, and you might have what you're looking for. But this is definitely user level, not library level, as container types need to be known before hand. I am not too interested in shipping a pre-templated set of containers for the built in types, either. I prefer the user to have that control, need the need arise to chance a namespace, like with str.h:
|
Beta Was this translation helpful? Give feedback.
-
You did a great and incredible work. I only created an array generic class that i needed .
I had not seen your library :-( i suggest you to evaluate to add a _Generic macro to your functions for C11.
This let's you write for example : vec_int_push_back(&a, 1); as push_back(vec_int, &a, 1); if your type is vec_int
or push_back(vec_double , &a, 1.0) if you use vec_double_push_back .
Beta Was this translation helpful? Give feedback.
All reactions