Showing posts with label cpp11_forward. Show all posts
Showing posts with label cpp11_forward. Show all posts

Jul 8, 2022

[C++] inline std::forward impl

Reference:
https://github.com/fmtlib/fmt/blob/b761f1279e2dfb950a7bf9ff7128d6b03b77b013/include/fmt/core.h#L204
https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html

{fmt}/core.h itself contains nice coding tips/idea

inline std::forward impl
i.e.
// An inline std::forward replacement.
#define FMT_FORWARD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)

Aug 12, 2018

[C++][recap] forward

https://en.cppreference.com/w/cpp/utility/forward


Perfect forwarding isn't really perfect. There are several kinds of arguments that cannot be perfectly forwarded, including (but not necessarily limited to):

  • 0 as a null pointer constant.
  • Names of function templates (e.g., std::endl and other manipulators).
  • Braced initializer lists.
  • In-class initialized const static data members lacking an out-of-class definition.
  • Bit fields.

For details consult the comp.std.c++ discussion, “ Perfect Forwarding Failure Cases,”referenced in the Further Information section of the course.