Рассмотрим следующий код. Безопасно ли дважды вызывать std::get со ссылкой rvalue на один и тот же кортеж?
Код: Выделить всё
template
void func(Tuple && tuple) {
f1(std::get(std::forward(tuple));
f2(std::get(std::forward(tuple));
}
int main() {
func(std::make_tuple(std::string(), std::string()));
}
Код: Выделить всё
template
void func(Optional && optional) {
if (optional.has_value()) {
f1(*std::forward(optional));//T && std::optional::operator*() &&
}
auto b = optional.has_value();//
Подробнее здесь: [url]https://stackoverflow.com/questions/79866975/is-it-ok-for-the-same-object-being-rvalue-used-twice-consecutively[/url]
Мобильная версия