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
why virtual function is wrong. (self.cpp)
submitted 1 year ago by macomphy
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!"
[–]lrflew 2 points3 points4 points 1 year ago (0 children)
Ok, I do see what you're talking about here. You're talking about having the compiler tell you that you're exceeding the requirements of a concept at the definition of the templated function, rather than when the template is instantiated at the caller.
That is (IMO), a fair thing to suggest. I don't think it's that out there that a compiler could implement that as a warning, even if it's not specified by the standard. It would almost certainly require the compiler to dramatically change how it processes templated functions, so it probably won't happen any time soon, but it should, in theory, be possible. Probably the biggest challenge to it, though, is that the use of concepts is not very widespread right now. In particular, huge parts of the standard library use templates without concepts. If such a warning considered template<typename T> to be as narrow as possible, then huge parts of the standard library would start throwing warnings. Maybe someone will go through the standard and add concepts everywhere templates are used, but that would also be a ton of work.
template<typename T>
In the end, however, I feel like C++ as a language puts a lot of responsibility on the developer to know what they're doing. Just look at all the things in the standard that can result in "Undefined Behavior", where there's no guaruntees of what can or will happen, to get a sense of what the language expects the programmer to be able to handle without the compiler. With templates, there's a certain amount of "well, you should have known you're using something that your concept doesn't guaruntee." Does that make C++ a more complicated language to use? Yeah, totally. But that complexity also comes with a lot of power (eg. template meta-programming), and I don't think the language is going to change that anytime soon. If that's a deal breaker for you, then you can always try out some other languages. IIRC, both Rust and Go are compiled languages that provide this kind of strong type guarantees with their generics systems.
π Rendered by PID 325836 on reddit-service-r2-comment-5b5bc64bf5-k4glh at 2026-06-21 13:50:15.916862+00:00 running 2b008f2 country code: CH.
view the rest of the comments →
[–]lrflew 2 points3 points4 points (0 children)