3 ms·
Maybe I'm the only one, but... why? What about by-hand-inlining `std::find` makes the code better?
by MauranKilom 3y ago
Maybe I'm the only one, but... why?
What about by-hand-inlining `std::find` makes the code better?
- Conscat 3y agoClang has a statement attribute `[[clang::always_inline]]` that automates this at a call site, but GCC only has a function attribute for it. You could wrap the function in a `[[gnu::flatten]]` function that takes the callable as a non-type template parameter in C++20 to do this, though, but that could be more aggressive than what you want. It also won't work for operators as easily as this. You can already expand macros at call site in any major C++ editor, so why not functions as well? I would like this mainly just for making source exploration easier. Visual Studio and Clion have a "peek" feature that does something similar, but as a purely UI element, but Emacs' implementation of peek from LSP works much worse.
- Conscat 3y agoCorrection, I actually just tried this. The wrapper does not work in GCC, but it does in Clang. https://godbolt.org/z/d3jMo36WY https://godbolt.org/z/d3jMo36WY
- sweetjuly 3y agoIt's great for doing security reviews! Often times with crazy template and macro ridden code, it's a challenge to even find the implementation for something. Sometimes it's easier to compile the binary, throw it into Ghidra, and look at the disassembly and decompilation to grok what the code is actually doing than try to bounce your way through a dozen templates and types.
- the-smug-one 3y agoI just want to know what code is actually called. This is often a pain in C++. I assume this code handles SFINAE etc.
- choppaface 3y agoCopy-pasta is typically a no-no, but this tool sure helps experiment especially when templates / types are complex. Moreover things like SFINAE, variadic functions, and macros can make some libraries really opaque. Stuff like loggers, pub-subs, SERDES code... there will be a lot of template complexity and other indirection where this tool would help dramatically in peeling back the layers and could be used in place of breakpoints or a traditional debugger. (And it can often be hard to set up a debug session for large systems). Can also be useful when you want to take an existing function and customize it for the call site versus write a new helper. For example maybe you want std::find_if() but instead of writing a lambda predicate you want some other code embedded into the body of the loop.