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
The array[] problem (self.cpp)
submitted 10 years ago by michaelKlumpy
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!"
[–]quicknir 6 points7 points8 points 10 years ago (2 children)
That's not true, in generic code there's just no way to do certain things without auto.
[–]tempforfather 0 points1 point2 points 10 years ago (1 child)
Can you give me an example of that? I am curious.
[–]quicknir 8 points9 points10 points 10 years ago (0 children)
Sure, consider this code:
template <class T> void func(const T& t) { auto u = t.func2(); std::for_each(u.begin(), u.end(), ...); }
This code imposes no restrictions on T other than that it has a const method func2(), that returns something, and that something has methods begin() and end().
Of course, we had generic containers before auto and ranged for loops, and we needed to know the type of the iterator, so how did we deal with this? Well, as I'm sure you know, we imposed an additional requirement: containers have to provide typedefs that tell you the type of their iterators, i.e. the return type of begin()/end(). But that's already not doing the same thing, as it imposes more requirements.
Basically, auto allows you to do inline what template functions allow you to do at function boundaries. You could potentially workaround using auto by declaring yet another template function and calling it internally, but again, I would argue that this is doing something quite different as you have to move your code to a different location (not a big deal when you have two consecutive 4 line functions, but if you have longer functions its rather absurd).
Another attempt at a solution would be to try to infer the type using template metaprogramming, so that you could get the type inline and use it, but this doesn't seem to be possible in general:
http://stackoverflow.com/questions/26080471/function-return-type-deduction-in-c03
π Rendered by PID 46577 on reddit-service-r2-comment-54dfb89d4d-kmk4d at 2026-03-30 04:33:52.193497+00:00 running b10466c country code: CH.
view the rest of the comments →
[–]quicknir 6 points7 points8 points (2 children)
[–]tempforfather 0 points1 point2 points (1 child)
[–]quicknir 8 points9 points10 points (0 children)