memesearch
Когда tuple умнее ручного сравнения

Когда tuple умнее ручного сравнения

Download Find similar pictures
Text on the meme
#include <tuple> struct A { int i; float f; }; bool greater_tie(const A& left, const A& right) { return std::tie(left.i, left.f) > std::tie(right.i, right.f); } bool greater(const A& left, const A& right) { return left.i > right.i || (left.i == right.i && left.f > right.f); } greater_tie(A const&, A const&): mov edx, DWORD PTR [rdi] mov eax, DWORD PTR [rsi] cmp DWORD PTR [rsi], edx jl .L1 mov eax, 0 je .L1 movss xmm0, DWORD PTR [rdi+4] comiss xmm0, DWORD PTR [rsi+4] seta al .L1: ret greater(A const&, A const&): mov edx, DWORD PTR [rsi] mov eax, DWORD PTR [rdi] cmp DWORD PTR [rdi], edx jg .L6 mov eax, 0 je .L10 .L6: ret .L10: movss xmm0, DWORD PTR [rdi+4] comiss xmm0, DWORD PTR [rsi+4] seta al ret
What it means

Слева показаны две реализации сравнения структур в C++, а справа — сгенерированный для них ассемблер. Шутка в том, что короткая реализация через std::tie неожиданно превращается в более длинный и сложный код, тогда как ручное сравнение компилируется компактнее. Мем используют программисты, когда абстракция оказывается менее эффективной или более запутанной, чем явный код. EN: Two C++ implementations for comparing structs are shown on the left, with their generated assembly on the right. The joke is that the short std::tie implementation unexpectedly turns into longer, more complicated code, while the manual comparison compiles into something more compact. The meme is used by programmers when an abstraction turns out to be less efficient or more confusing than explicit code.

Objects
Tags
Source
Type
image
Size
800×406 · 43.9 KiB
Mood
ироничный, технический
Language
ru
Added