RVO vs. TCO

Liste des GroupesRevenir à cl c++ 
Sujet : RVO vs. TCO
De : news.5.maazl (at) *nospam* spamgourmet.org (Marcel Mueller)
Groupes : comp.lang.c++
Date : 09. Jun 2025, 16:16:12
Autres entêtes
Organisation : MB-NET.NET for Open-News-Network e.V.
Message-ID : <1026trt$1v2oi$1@gwaiyur.mb-net.net>
User-Agent : Mozilla Thunderbird
Hello,
does a tail call prevent return value optimization?
vector<XXX> func1();
vector<XXX> func2()
{
   if (some_condition)
     return func1();
   vector<XXX> result;
   // populate result
   return result;
}
AFAIK RVO requires all paths of a function to return the same instance.
But can this also work with tail calls like func1()?
If not, the following work around could be preferred:
vector<XXX> func3()
{
   vector<XXX> result;
   if (some_condition)
     result = func1(); // forces move
   else
     ; // populate result
   return result;
}
Marcel

Date Sujet#  Auteur
9 Jun 25 o RVO vs. TCO1Marcel Mueller

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal