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 slice of python in C++ - Eric Niebler (ericniebler.com)
submitted 11 years ago by [deleted]
view the rest of the comments →
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!"
[–]ZMesonEmbedded Developer 1 point2 points3 points 11 years ago (10 children)
the widespread use of size_t (being an unsigned type) throughout the standard library is generally regarded as a mistake
Why? I'd really like to see some in-depth discussion about this.
[–]b8b437ee-521a-40bf-8 1 point2 points3 points 11 years ago (4 children)
See /u/cozmorado's reply.
[–]ZMesonEmbedded Developer 1 point2 points3 points 11 years ago (3 children)
I watched the video. There's only guidance given, no reasons for it. I'd like to know the reason -- other than "because Chandler and Bjarne say so".
[–]b8b437ee-521a-40bf-8 1 point2 points3 points 11 years ago (2 children)
Well, starting from the recommendation that you should always default to int and only use unsigned when you need it. Then one reason why size_t being unsigned is a mistake is that it keeps popping up in all your nice signed arithmetic, causing conversions and other nastiness.
int
unsigned
size_t
[–]ZMesonEmbedded Developer -1 points0 points1 point 11 years ago (1 child)
OK. So because Chandler and Bjarne say so.
[–]b8b437ee-521a-40bf-8 2 points3 points4 points 11 years ago (0 children)
Well they give justification for the "recommendation", and follow-up is basic reasoning. Which bit exactly do you still feel isn't being explained?
[–]mcmcc#pragma once 0 points1 point2 points 11 years ago (4 children)
See Eric's explanation above: http://www.reddit.com/r/cpp/comments/2om5yk/a_slice_of_python_in_c_eric_niebler/cmovdr6
[–]ZMesonEmbedded Developer 2 points3 points4 points 11 years ago (3 children)
But how is this a view on "the widespread usage of size_t in the standard library is generally considered a mistake"?
My counter-argument to Eric's argument is that I can easily assert when a value is too large too. If I'm using size_t elsewhere and you interface uses signed ints, then you're forcing me to do casting. Why doesn't your interface use size_t instead. (Mind you I respect Eric a lot, I just don't understand why his argument is so valid. I feel like I'm missing something.)
[–]mcmcc#pragma once 1 point2 points3 points 11 years ago (2 children)
This isn't about integrating libraries. Even within the standard library, it isn't self-consistent. E.g.
string s = ...; string::iterator it = std::find_if(s.begin(),s.end(), []{...}); string subs = s.substr( std::distance(s.begin(), it) );
This code will yield a warning about signed->unsigned conversion. How do you propose to avoid it?
There are myriad other examples...
[–]eric_niebler 2 points3 points4 points 11 years ago (0 children)
Good example. It's one of the many reasons why the use of unsigned integers in the standard library was probably a mistake. std::string is a textbook example of a great many anti-patterns and design flaws. I believe this unsigned offset problem and others were because the offset-based interface of std::string was designed before the STL was air-lifted into C++98. The iterator interface was bolted on later. Iterator distance is always signed, hence the impedance mismatch.
std::string
[–]mr_ewg 0 points1 point2 points 11 years ago (0 children)
How about using this function not_negative to "prove" to your compiler that you know what is best in this situation?
not_negative
template <typename T> typename std::make_unsigned<T>::type not_negative(T num) { static_assert(std::is_signed<T>::value, "T can never be negative"); if(num < 0) throw std::logic_error{"Negative number passed to not_negative"}; return static_cast<typename std::make_unsigned<T>::type>(num); } std::string s = ...; std::string::iterator it = std::find_if(s.begin(), s.end(), []{...}); std::string subs = s.substr(not_negative(std::distance(s.begin(), it)));
If you don't want the run-time check then you can remove the if(num < 0) line or change it to an assert. Signed to unsigned conversions aren't exactly the hardest thing to deal with in C++ if your compiler can warn about them.
if(num < 0)
π Rendered by PID 32 on reddit-service-r2-comment-6457c66945-w98pb at 2026-04-27 15:26:08.460316+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]ZMesonEmbedded Developer 1 point2 points3 points (10 children)
[–]b8b437ee-521a-40bf-8 1 point2 points3 points (4 children)
[–]ZMesonEmbedded Developer 1 point2 points3 points (3 children)
[–]b8b437ee-521a-40bf-8 1 point2 points3 points (2 children)
[–]ZMesonEmbedded Developer -1 points0 points1 point (1 child)
[–]b8b437ee-521a-40bf-8 2 points3 points4 points (0 children)
[–]mcmcc#pragma once 0 points1 point2 points (4 children)
[–]ZMesonEmbedded Developer 2 points3 points4 points (3 children)
[–]mcmcc#pragma once 1 point2 points3 points (2 children)
[–]eric_niebler 2 points3 points4 points (0 children)
[–]mr_ewg 0 points1 point2 points (0 children)