mpreal icon indicating copy to clipboard operation
mpreal copied to clipboard

Can math functions return by value without const type qualifier?

Open lhprojects opened this issue 4 years ago • 2 comments

Simple program failed to compile with VS2019 (It should be the same with the other compilers).

void foo(mpreal &&);
mpreal a,b;
foo(a+b); // a+b has a type of const mpreal

Note the signature of operator+: inline const mpreal operator+(const mpreal& a, const mpreal& b). It seems quite unnormal that returning value with a const qualifier. I don't know if there is any benefit by return value with const qualifier. However, there is clearly a drawback.

lhprojects avatar Sep 04 '21 17:09 lhprojects

Thank you for reporting this. I added const qualifier in 2008, have no idea why. It didn't cause any issues back then. Clearly we need to change this to support move semantic. Will consider doing this in future.

advanpix avatar Jan 18 '22 10:01 advanpix

Thank you for reporting this. I added const qualifier in 2008, have no idea why. It didn't cause any issues back then. Clearly we need to change this to support move semantic. Will consider doing this in future.

+1, THANKS. It works well now!

bashanbro avatar Mar 25 '23 23:03 bashanbro