3 ms·
Consider a function that takes two references and returns a reference. Which of the two input reference lifetimes does the lifetime of the returned reference li
by dodobirdlord 7y ago
Consider a function that takes two references and returns a reference. Which of the two input reference lifetimes does the lifetime of the returned reference live in? Trick question, the function returns a static lifetime reference to a constant.
Is this an anti-pattern? There are many situations where this would be the most efficient implementation. The compiler can frequently elide lifetimes, it only needs them when it's ambiguous. Sometimes you need to pass two references and return a reference.
- unexaminedlife 7y agoI think the question for me (in this thought experiment) will be "what will the code look like if I try to avoid this?". And what are the repercussions? From a performance and/or readability / comprehension standpoint (or any other perspective).