News for hackers. Stuff that matters.
Re:Lvalues, rvalues, glvalues, prvalues, xvalues, help (2018) by ncmncm on Thursday April 11, 2019 @07:46PM (#19640451)
Code like that is the bane of my existence. Give me `T2 function(T1)` every time. Besides being overwhelmingly clearer, I can use it in just one line. The other needs at least 3, more commonly 5, lines packed around it, so less than 20% of your code actually does anything useful toward the problem it is supposed to solve. Five times longer means you have five times the bugs.

Besides being horrible style, operating on references cripples the optimizer. "Avoid accidental copying"? What good is that if it's slower than if you did the copy?

Re:Lvalues, rvalues, glvalues, prvalues, xvalues, help (2018) by signa11 on Thursday April 11, 2019 @08:03PM (#19640570)
serious question: would you throw an exception if T2 cannot be created ? or use a variant data-type ? or something else altogether?
Re:Lvalues, rvalues, glvalues, prvalues, xvalues, help (2018) by ncmncm on Friday April 12, 2019 @10:31PM (#19650741)
Generally, yes, throw.

Sometimes an optional is better, such as when downstream already takes one.

Occasionally, checking whether the operation (and a bunch of others) would succeed is best, particularly in high-rel/high-av systems. There, you are probably also logging, first, what you are about to attempt.

Re:Lvalues, rvalues, glvalues, prvalues, xvalues, help (2018) by bigcheesegs on Thursday April 11, 2019 @08:52PM (#19640880)
Use a variant type like llvm::Expected.
Re:Lvalues, rvalues, glvalues, prvalues, xvalues, help (2018) by signa11 on Thursday April 11, 2019 @11:07PM (#19641593)
yup, that's what i thought. i generally tend to use a construct simiar to 'error_or' though. that wrapped within a macro (^^) makes the whole invokation quite bearable