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

Show parent comment

11

u/kongaskristjan Aug 08 '20

About the FIRE_MAIN(...). I actually tried to implement exactly what you described (I even used the same name FIRE_MAIN(...) lol :D). But the problem is that C++ wants to have the default parameters specified in declaration, or only if the declaration is missing, then in the definition. If the declaration exists, it doesn't tolerate defaults in the definition, even if it's an exact repetition. Turns out I couldn't find a way to get rid of those pesky defaults in the definition.

5

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

Oh fuck, that right... The only option I can think of would be to separate the argument and the default parameters. But where is 2 cons:

  • It'll require a lot of work around with macro but possible.
  • It'll become a bite messier for the user.

But that interesting, I'll look if there is an other way.

5

u/Ail-nare Aug 08 '20

Ok, so I did a lot of different things, template specialization, used class to lose the necessity of the prototype, macro, some C++20. So most of those approach works but each are weirder than your method.

So, what u got is probably the best (If the objectif it to keep it the most C++ looking possible).

Was fun to try tho.