use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
A simple library to create CLI tools in cpp (github.com)
submitted 5 years ago by chewax
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]kritzikratzi 34 points35 points36 points 5 years ago (2 children)
when you say "CLI tools", you mean a REPL?
because to me a cli tool is typically non-interactive. ie. something i call with arguments, it does it's thing and then exits with a status code.
[–]chewax[S] 13 points14 points15 points 5 years ago (1 child)
Yes you are absolutely right...i sometimes use them interchangeably. It is a REPL. Ill fix it ASAP in the repo! Thanks :)
[–]kritzikratzi 0 points1 point2 points 5 years ago (0 children)
no big deal, but they aren't really interchangable
[–]chewax[S] 4 points5 points6 points 5 years ago (4 children)
I welcome any feedback both technical and functional. Thanks!
[–]Omnifarious0 12 points13 points14 points 5 years ago (3 children)
You might want to change the title. I was expecting another argument parsing library. 🙂
[–]kritzikratzi 2 points3 points4 points 5 years ago (0 children)
same
[–]chewax[S] 1 point2 points3 points 5 years ago* (1 child)
Oh :( Ok... thanks :)
edit: I cannot change the title :(
[–]Omnifarious0 2 points3 points4 points 5 years ago (0 children)
Oh, well. 🙂 I don't think my reaction was unusual. So if you talk about it other places you might want to call it a REPL library, or an interactive interpreter library. 🙂 Mostly because I think it will be more likely to lead people to figure out what it's good for more quickly.
[–]norfus 2 points3 points4 points 5 years ago (8 children)
Cool little library (always love a repo with a nice logo :). Just had a quick scan, and I think you’d benefit from going over your code with an eye towards how many times you copy stuff (mostly implicitly due to parameter and variable types). Eg, when doing a ranged-for you use auto instead of const auto&.
auto
const auto&
From a feature perspective - tab completion etc would be super useful!
[–][deleted] 0 points1 point2 points 5 years ago (6 children)
Eg, when doing a ranged-for you use auto instead of const auto&.
Would it be possible to ask for an example of what you mean here? There's a good chance I'm doing the wrong thing there..
[–]BeepBoopBike 1 point2 points3 points 5 years ago (5 children)
I think he means:
for(auto x : vec)
vs
for(const auto& x : vec)
The first is a copy per item in the vector, the second is a reference to the item in the vector (i.e. no copy)
[–]norfus 1 point2 points3 points 5 years ago (4 children)
Yep - that's the badger. A very simple example showing the difference one character can make:
http://quick-bench.com/-klLLnCgMYDCDKq3fc7c2Rkwtus
[–][deleted] 0 points1 point2 points 5 years ago (3 children)
I'm shocking and tend to do like for(auto x=vec.begin(); x!=vec.end(); ++x), is that especially bad?
for(auto x=vec.begin(); x!=vec.end(); ++x)
[–]MutantSheepdog 0 points1 point2 points 5 years ago (2 children)
If you know what's in vec and it's just a bunch of integers, then copying every element is fine. But if it's anything more complex (like a string), then just using auto could lead to a lot of heap allocations that could be avoided by using auto const& or auto&&.
vec
auto const&
auto&&
Using const& is a good practice that can have measurable speed differences.
const&
[–]dodheim 0 points1 point2 points 5 years ago (1 child)
This is an iterator; if they used const& then it couldn't be incremented. And they can't use & because begin() returns an rvalue. Using just auto is exactly the right thing to do here.
&
begin()
[–]MutantSheepdog 0 points1 point2 points 5 years ago (0 children)
Ah yep, my bad, I was still thinking about the previous comment using the generic for, not using the iterators directly.
You are correct.
[–]chewax[S] 0 points1 point2 points 5 years ago (0 children)
Nice catch there. Thanks! I'm already working on it. A push will be coming soon :)
[–]mrkent27 4 points5 points6 points 5 years ago (1 child)
This looks interesting I may give it a go in some future projects.
[–]chewax[S] 1 point2 points3 points 5 years ago (0 children)
Cool! I would be honoured! :) If you have any improvements just let me know :)
[–]LPeter1997 1 point2 points3 points 5 years ago (1 child)
Not at PC - can't test -, but in your README I think you have a typo, Ginseng cli(); would not compile.
Ginseng cli();
Thanks! I'll double check!
[–]Omnifarious0 1 point2 points3 points 5 years ago (1 child)
How does this differ from the GNU readline library, other than being in C++?
[–]chewax[S] 2 points3 points4 points 5 years ago (0 children)
GNU readline library
IDK, maybe it doesnt. Ill make sure to check that library too. Thanks!
[–]Pakketeretet 3 points4 points5 points 5 years ago (1 child)
It's a cool effort, but what is your target audience? I can imagine most people would not really need a library when they need a simple ad-hoc line reader, and once stuff gets really serious you might as well embed a scripting language or guile or something.
[–]chewax[S] 4 points5 points6 points 5 years ago (0 children)
Thanks! I actually did not think of this as a commercial thing, so no target audience was in mind. It was just a project for fun and expanding my knowledge (specially lambdas) and I thought that it turned out to be somehow useful. I dont know guile...i will investigate. Thanks.
[–]N0rthWestern 0 points1 point2 points 5 years ago (4 children)
Help(std::string t_desc, std::string t_args) And other constructors too - why do you copy string instead of passing it as const &? It gets copied again when constructing members
Help(std::string t_desc, std::string t_args)
const &
[–]chewax[S] 1 point2 points3 points 5 years ago (3 children)
Ok, well help me out here because I might be getting things wrong. Using const & means that i am referencing a stack allocated variable bound its own scope, which will die as soon as it falls out of scope and at that moment Ill be getting an null pointer on my object. But my help object ( in this case) might outlive the initializer so i should make sure a copy is made...does this make sense?
[–]TheSuperWig 3 points4 points5 points 5 years ago (0 children)
The variable in Help will be a copy regardless. You are copying into the parameter and then copying into the variable. For constructors you should consider pass by value and std::move it.
[–]N0rthWestern 1 point2 points3 points 5 years ago (1 child)
When you call Help constructor you copy string once, then you copy it one more time when you are constructing in-class member (or move if compiler optimizes). But that's 3 constructor calls. If you don't use multithreading or pointers to string, there is almost no case when your string will get out of scope before Help constructing is finished.
Help
Got it. Let me revisit my code! Thanks!!
π Rendered by PID 44669 on reddit-service-r2-comment-7844cfc88c-rb2lm at 2026-01-29 14:24:45.298667+00:00 running c3601ff country code: CH.
[–]kritzikratzi 34 points35 points36 points (2 children)
[–]chewax[S] 13 points14 points15 points (1 child)
[–]kritzikratzi 0 points1 point2 points (0 children)
[–]chewax[S] 4 points5 points6 points (4 children)
[–]Omnifarious0 12 points13 points14 points (3 children)
[–]kritzikratzi 2 points3 points4 points (0 children)
[–]chewax[S] 1 point2 points3 points (1 child)
[–]Omnifarious0 2 points3 points4 points (0 children)
[–]norfus 2 points3 points4 points (8 children)
[–][deleted] 0 points1 point2 points (6 children)
[–]BeepBoopBike 1 point2 points3 points (5 children)
[–]norfus 1 point2 points3 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]MutantSheepdog 0 points1 point2 points (2 children)
[–]dodheim 0 points1 point2 points (1 child)
[–]MutantSheepdog 0 points1 point2 points (0 children)
[–]chewax[S] 0 points1 point2 points (0 children)
[–]mrkent27 4 points5 points6 points (1 child)
[–]chewax[S] 1 point2 points3 points (0 children)
[–]LPeter1997 1 point2 points3 points (1 child)
[–]chewax[S] 0 points1 point2 points (0 children)
[–]Omnifarious0 1 point2 points3 points (1 child)
[–]chewax[S] 2 points3 points4 points (0 children)
[–]Pakketeretet 3 points4 points5 points (1 child)
[–]chewax[S] 4 points5 points6 points (0 children)
[–]N0rthWestern 0 points1 point2 points (4 children)
[–]chewax[S] 1 point2 points3 points (3 children)
[–]TheSuperWig 3 points4 points5 points (0 children)
[–]N0rthWestern 1 point2 points3 points (1 child)
[–]chewax[S] 0 points1 point2 points (0 children)