dafky2000 / simplectemplate

Simple C Template library to expand placeholders in a template string, simple alternative to mustache.github.io that doesn't require JSON as data input.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

One array to submit entire key/value pair

dafky2000 opened this issue · comments

const char* item_list[] = { 
  "data.key", "replacement",
  "data.key2", "replacement2",
  ....
};
render_template("My {{data.key}} template {{data.key2}}", 2, item_list);

Although this would work much nicer, I didn't realize function overloading is not a thing in C. There some tricks but differentiating 2 arrays from 1 array with the exact same number of elements is not easy/possible?... This would work better if they were not arrays, arrays seem to pass element as an argument when you use argument expansion (...).

Leaving this open for discussion and maybe making this the new standard for v1? Thoughts?

There's some thoughts on it at
https://stackoverflow.com/questions/479207/function-overloading-in-c/25026358#25026358

In the time since this question was asked, standard C (no extensions) has effectively gained support for function overloading (not operators), thanks to the addition of the _Generic keyword in C11. (supported in GCC since version 4.9)

(Overloading isn't truly "built-in" in the fashion shown in the question, but it's dead easy to implement something that works like that.)

Awesome thanks! I saw this too but I was unsure how well adopted c11 is.

and this brings up another question too. could we use the Generic functionality behind an ifdef for c11 support?

Closed via #52