Код: Выделить всё
#include
#include
#include
#include
template
decltype(auto) apply1(F&& func, T&& val){
if constexpr(std::is_lvalue_reference{}){
auto& [m1] = val;
return std::invoke(std::forward(func), m1);
} else {
auto&& [m1] = std::forward(val);
return std::invoke(std::forward(func), std::forward(m1));
}
}
//tests
struct obj{int v;};
struct data{obj o;};
void ref(obj&){std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78530873/how-to-correctly-and-elegant-implement-the-apply-function-for-structured-binding[/url]