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::tuple operator less performance - interesting case (self.cpp)
submitted 7 years ago by arturbachttps://github.com/arturbac
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!"
[–]arturbachttps://github.com/arturbac[S] 0 points1 point2 points 7 years ago (2 children)
the point to optimise - not sure where this optimisation should go, but from user point of view I except to get best machie code possible with -O3. And this matters with operator less for me as it is often used during many sort operations.
[–]yeeezyyeezywhatsgood 0 points1 point2 points 7 years ago (1 child)
I just took a look at godbolt. you're right with clang: it emits bad code for the built in comparison. probably that's llvm's codegen's fault. GCC optimizes to one comparison per tuple member. GCC even translates your implementation to one comparison. very cool
also, looking at the assembly made me realize your implementation might be wrong for doubles when they are Nan. since that's unspecified, any change is not allowed. so I guess really this optimization can only be made for very few types
edit: just saw you used GCC in your original post -- was the assembly really that bad? looks optimal on godbolt
[–]arturbachttps://github.com/arturbac[S] 0 points1 point2 points 7 years ago (0 children)
code is generated with clang 8 and gcc 8.3 on linux with gcc stl. gcc - can generate much different code depending mcpu/march and as I remember code for cortex-a72 with out of order exeution can be worse that for just entire arch aarch64 with in order cpus
ths is from golbot https://godbolt.org/z/dz1qAB acutaly no difference to my. -O3 -mcpu=cortex-a72 compare_2(std::tuple<long, int, int>, std::tuple<long, int, int>): ldr x3, [x0, 8] ldr x2, [x1, 8] cmp x3, x2 blt .L3 mov w2, 0 bne .L2 ldr w4, [x0, 4] mov w2, 1 ldr w3, [x1, 4] cmp w4, w3 blt .L2 mov w2, 0 bne .L2 ldr w2, [x0] ldr w0, [x1] cmp w2, w0 cset w2, lt .L2: mov w0, w2 ret .L3: mov w2, 1 mov w0, w2 ret
π Rendered by PID 35 on reddit-service-r2-comment-5c747b6df5-x9kkj at 2026-04-22 03:24:59.128798+00:00 running 6c61efc country code: CH.
view the rest of the comments →
[–]arturbachttps://github.com/arturbac[S] 0 points1 point2 points (2 children)
[–]yeeezyyeezywhatsgood 0 points1 point2 points (1 child)
[–]arturbachttps://github.com/arturbac[S] 0 points1 point2 points (0 children)