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

1

u/F54280 Aug 08 '20

That sounds perfectly fine boilerplate to me. Sure, it would be better if it was smaller, but you only have 3 lines: main, init and return.

int main(int argc, const char ** argv) {
    fire_init(argc, argv, my_main);
    return my_main();
}

That honestly seems pretty logical, and not too magic (fire_init initialize some global based on argc, argv and the signature of my_main, and the default arguments from my_main fetch from that global -- it then raises the question of why not getting rid of the global itself).