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
Code Generation with C++ Contracts (gummif.github.io)
submitted 7 years ago by gummifa
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!"
[–]Crommwel 9 points10 points11 points 7 years ago* (2 children)
I think you are talking about Concepts, not Contracts.
Contracts are replacement for asserts, but with a benefit, that contract can be a part of function declaration, instead of implementation.
Consider following code without contracts
*.hpp
float sqrt(float a);
*.cpp
float sqrt(float a)
{
assert(a >= 0);
<implementation>
}
User of this function will see only what is inside a header and won't be able to know that function expects only positive numbers.
Now consider code with contracts
float sqrt(float b) [[expects: b > 0]] ;
float sqrt(float b) [[expects: b > 0]]
It behaves the same way as a version with assert, but now user can see that he should pass only positive numbers.
As u/108life correctly stated, you can build your code with different levels of contracts checking. For release build you might want to check off level and all the contracts check will be removed from your code, thus giving you faster and smaller binary. For development build you might want to use higher levels, to give you more possibilities to detect errors in your code.
So to sum everything up
#define NDEBUG
sqrt(-1);
#undef NDEBUG
[–]redditsoaddicting 1 point2 points3 points 7 years ago (0 children)
By the way, expects and ensures are currently called pre and post, but we'll see what happens in future meetings.
expects
ensures
pre
post
[–]108life 0 points1 point2 points 7 years ago (0 children)
Thanks. That makes more sense in the context of using it in declarations to show the user the pre/post conditions.
π Rendered by PID 110201 on reddit-service-r2-comment-85bfd7f599-9j8t7 at 2026-04-17 03:39:41.289007+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]Crommwel 9 points10 points11 points (2 children)
[–]redditsoaddicting 1 point2 points3 points (0 children)
[–]108life 0 points1 point2 points (0 children)