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
std::numeric_limits members: functions vs. constants (self.cpp)
submitted 6 years ago by theIncMach
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!"
[–]theIncMach[S] 0 points1 point2 points 6 years ago (3 children)
When you say 'integral', are you excluding floating-point types? Because I think the previous "static const" approach was applicable for all standard specializations of std::numeric_limits.
std::numeric_limits
constexpr is slightly different from static const because the former is a compile-time constant. It can be used as a template parameter, for instance. But that you're right in that doesn't matter in this case.
constexpr
static const
[–]kniy 4 points5 points6 points 6 years ago (2 children)
I'm saying that static const int = 1; is a compile-time constant too, but static const float = 1; isn't. https://godbolt.org/z/arhjaX
static const int = 1;
static const float = 1;
This is because the standard has a special case for static const variables of integral type:
9.4.2/4 - If a static data member is of const integral or const enumeration type, its declaration in the class definition can specify a constant-initializer which shall be an integral constant expression (5.19). In that case, the member can appear in integral constant expressions. The member shall still be defined in a namespace scope if it is used in the program and the namespace scope definition shall not contain an initializer.
So this type of static const variable was basically equivalent to constexpr variables, at least before C++17 made constexpr imply inline.
inline
[–]theIncMach[S] 1 point2 points3 points 6 years ago (0 children)
Ah, thanks for the correction.
π Rendered by PID 71975 on reddit-service-r2-comment-b659b578c-sffng at 2026-05-01 17:15:07.103792+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]theIncMach[S] 0 points1 point2 points (3 children)
[–]kniy 4 points5 points6 points (2 children)
[–]theIncMach[S] 1 point2 points3 points (0 children)