Open Eczbek opened 5 days ago
Why does the FWD
macro use VA_ARGS when it's not possible to use it with any number of arguments other than 1?
Also, major compilers recently got optimizations for std::forward
and std::move
to behave just like the cast even in unoptimized debug builds, so there's less of a need for such a macro.
In my own code, I only use macros for excessively repetitive code to make it easier to keep the actual differences in view and aligned. When it comes to just saving typing like in the examples in that link, I find macros make it more difficult to read the code.
@LB--
Why does the
FWD
macro use VA_ARGS when it's not possible to use it with any number of arguments other than 1?
The macro must accept any number of arguments because the preprocessor doesn't recognize <>
and []
, e.g. something like foo<int, int>
would actually count as 2 arguments.
Also, major compilers recently got optimizations for
std::forward
andstd::move
to behave just like the cast even in unoptimized debug builds
True, but the point of this macro is to make forwarding less verbose. With the FWD
macro you don't need to pass both a type and a value, instead you just pass the value. I suppose this aspect could be up to preference.
Channel This is a C++Weekly episode request, or perhaps just an interesting idea to mention.
Topics Macros in metaprogramming! Some common ones like
FWD
,ARROW
, andLIFT
: https://godbolt.org/z/5dbqqv8x8Length Not sure how much this topic can be explored