xieite::temp()

Defined in fragment xieite:temp
(header-only: <xieite/fn/temp.hpp>)


Creates a temporary object which lives for the duration of the full expression which contains it.
Can be used for ignoring output parameters (see example).


Declaration

template<typename T>
[[nodiscard]] constexpr T& temp(T&& value = {}) noexcept;


Example

import xieite;

void bad_api(int a, int b, int* out) {
	int sum = a + b;
	*out = sum;
	xieite::dump(sum);
}

int main() {
	// Don't care about output parameter
	bad_api(1, 2, &xieite::temp<int>());
}
Output:
3
View in Compiler Explorer