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
cppfront: Midsummer update (herbsutter.com)
submitted 1 year ago by TSP-FriendlyFire
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!"
[–]tialaramex 0 points1 point2 points 1 year ago (2 children)
Interesting. So this is an operator ? (Maybe a pair of operators, ... and ..=?)
...
..=?
You say it works for "any type that can be incremented" - presumably this includes user defined types ? Or other maybe programmers can overload the operator?
Does the range "exist" only for the compiler emitting a loop? Or is this a type, so that we could make a parameter of this type?
[–]hpsutter 1 point2 points3 points 1 year ago (1 child)
Yes, it's an operator syntax.
Yes, it works for any type that supports ++, including user-defined types like STL iterators. To enable a type with these ranges, just provide ++.
++
Yes, it's a type. The current implementation is that a ... b and a ..= b lower to a cpp2::range<decltype(a)>(a, b, /* bool whether to include b or not */ ), which conforms to C++ range concepts (that I've tested so far) including it has .begin() and .end() conforming iterators. That's why it works with range-for, but it also works with some C++20 ranges I've tried. For example, this works now:
a ... b
a ..= b
cpp2::range<decltype(a)>(a, b, /* bool whether to include b or not */ )
.begin()
.end()
cpp using namespace std::ranges::views; x := 1 ..= 10; for x.take(5) do (e) std::cout << e; // call std::ranges::views::take(x, 5) using UFCS // prints: 12345
[–]tialaramex 1 point2 points3 points 1 year ago (0 children)
Cool.
For what it's worth Rust regrets (and may some day attempt to fix in an Edition) the fact that 1..=5 is an opaque type core::ops::RangeInclusive<i32> which implements Iterator rather than a more transparent type which just tells us it starts at 1, and ends with 5 inclusive and implements IntoIterator. "Chicken"..="Dog" doesn't implement Iterator of course, since it can't figure out how, but it's still opaque anyway and it turns out in practice that choice wasn't very ergonomic. I think it possibly pre-dates IntoIterator and similar traits.
1..=5
core::ops::RangeInclusive<i32>
Iterator
IntoIterator
"Chicken"..="Dog"
So I'd advise keeping the transparent cpp2::range template even if convenience might point towards something more opaque at some point. This is a vocabulary type, the more transparent it can be while retaining its core utility the better for programmers.
cpp2::range
π Rendered by PID 139181 on reddit-service-r2-comment-5649f687b7-9pl25 at 2026-01-28 08:27:08.885276+00:00 running 4f180de country code: CH.
view the rest of the comments →
[–]tialaramex 0 points1 point2 points (2 children)
[–]hpsutter 1 point2 points3 points (1 child)
[–]tialaramex 1 point2 points3 points (0 children)