Код: Выделить всё
template
function_ref(F&& f) noexcept;
< /code>
[list]
[*] Инициализирует границу с помощью std :: addressof (f) < /code> и thunk-ptr с
адрес функции Thunk. Эта перегрузка участвует в разрешении перегрузки только если:
std::remove_cvref_t[*]
Код: Выделить всё
std::is_member_pointer_v[*]
Код: Выделить всё
/\*is-invocable-using\*/[/list]
It seems that the ctor allows the caller to pass in an expiring functor and uses the dangling reference to invoke the Dead Functor. Приведенный ниже код может продемонстрировать проблему. < /P>
Код: Выделить всё
#include
std::function_ref f() {
auto n = 1;
auto const fn = [n](int m) { return n + m; };
return std::function_ref(std::move(fn)); // eligible for ctor 2.
}
int main() {
auto fn_ref = f();
// fn_ref is now referencing to a dead functor!
return fn_ref(2); // BANG!
}
Код: Выделить всё
template
void ref(const T&&) = delete;
template
void cref(const T&&) = delete;
Почему стандарт не просто отклоняет аргумент функционирования, если это Rvalue-reference (включая && и const && )?
Подробнее здесь: https://stackoverflow.com/questions/796 ... r-than-dis
Мобильная версия