xte::lvalue()

Defined in header <xte/math/lvalue.hpp>

Casts to lvalue.


Definition

inline constexpr auto lvalue = [][[nodiscard]](auto&& x) static noexcept -> decltype(x)& { /* ... */ };



Examples

#0
static_assert(^^int& == ^^decltype(xte::lvalue(0)));
[View in Compiler Explorer]

#1
std::println("{}", *std::ranges::find_if(
	xte::lvalue(xte::array { 1, 2, 3 }),
	[](int x) { return x > 1; }
));
Output:
2
[View in Compiler Explorer]

#2
void bad_api(int a, int b, int* sum) {
	*sum = a + b;
	std::println("sum: {}", *sum);
}

// Don't care about out-parameter
bad_api(1, 2, &xte::lvalue(0));
Output:
sum: 3
[View in Compiler Explorer]