XIEITE_FWD(), XIEITE_FWD_PRVALUE(), XIEITE_FWD_PRVALUE_LOCAL()

Defined in header <xieite/fwd.hpp>
(header-only: <xieite/pp/fwd.hpp>)


Replacements for std::forward.


Definitions

#0
#define XIEITE_FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
Functions exactly like std::forward without requiring a template argument.

#1
#define XIEITE_FWD_PRVALUE(...) /* ... */
Based on #0, but includes special cases:
- Does nothing with prvalues: std::same_as<decltype(XIEITE_FWD_PRVALUE(0)), int>
- Avoids pessimization through temporary materialization (see example)
- Does nothing with lambda expressions: XIEITE_FWD_PRVALUE([] {})
Internally uses a lambda with no capture-default.

#2
#define XIEITE_FWD_PRVALUE_LOCAL(...) /* ... */
Same functionality as #1, but internally uses a lambda with a reference capture-default.


Example

#include <xieite/fwd.hpp>
import std;

struct S {
	S() { std::println(__PRETTY_FUNCTION__); }
	S(const S&) { std::println(__PRETTY_FUNCTION__); }
	S(S&&) { std::println(__PRETTY_FUNCTION__); }
	~S() { std::println(__PRETTY_FUNCTION__); }
	S& operator=(const S&) { std::println(__PRETTY_FUNCTION__); return *this; }
	S& operator=(S&&) { std::println(__PRETTY_FUNCTION__); return *this; }
};

int main() {
	{ S s = std::forward<S>(S()); }
	std::print("====================\n");
	{ S s = XIEITE_FWD_PRVALUE(S()); }
}
Possible output:
S::S()
S::S(S&&)
S::~S()
S::~S()
====================
S::S()
S::~S()