r/cpp • • Aug 08 '20

Create a fully functioning command line interface with 1.5 lines of code (wo. include statement)

https://github.com/kongaskristjan/fire-hpp
230 Upvotes

62 comments sorted by

View all comments

10

u/Ail-nare Aug 08 '20 edited Aug 08 '20

Hey, since you use a macro ('FIRE(fnptr *)'), why don't you make a macro ('FIRE_MAIN(...)'). So that this macro will be used instead of the name of the function, this macro do 3 thing:

  • Declare the prototype of the function (possible, thx to the argument given as parameters).

  • Than what used to do ('FIRE(fnptr *)').

  • Than rewrite the prototype without the ';' to declare the function.

That way it will look more like unit_tests function, like Google test or criterion. I think people are more used to this.

Anyhow, if I one day have the occasion I'll probably use your lib, it's more than clean enough to me.

Oh and last thing, with this commande "g++ *.cpp -o binary_name", the argument of the '-o' flag is given without a '='. I didn't see a way with your lib? Or am I just blind?

Edit:grammar, sorry for my English.

2

u/kongaskristjan Aug 08 '20 edited Oct 04 '20

About g++ *.cpp -o binary_name.

If you write FIRE(...), -o is automatically associated with binary_name. However, if you write FIRE_NO_SPACE_ASSIGNMENT(...), it's not associated. However, currently only FIRE_NO_SPACE_ASSIGNMENT(...) allows positional arguments and unlimited number of arguments that are needed right here. So no, unfortunately it is not possible at the moment.

It turns out that implementing positional arguments with FIRE(...) requires some rather complex try/catch logic to actually pull off. I consider implementing this for v0.2 or v0.3.

Edit: error in logic.

Edit2: It is now possible to call FIRE(...) with positional/variadic arguments.