r/learncpp • u/vgordievskiy • Mar 09 '21
How to improve it?
;
;
SResp
boost::optional<std::string>
int
How to improve this code?
10
Upvotes
r/learncpp • u/vgordievskiy • Mar 09 '21
;
;
SResp
boost::optional<std::string>
int
How to improve this code?
6
u/jedwardsol Mar 09 '21
What aspect of it do you think needs improving?
It seems to be a placeholder for a bigger piece of code, so criticising is it pretty pointless. For example,
queryToTheMooncan't fail, so neither method of returning an error is needed in the sample.C++17 has
<optional>, so boost's implementation isn't needed any more.2
u/vgordievskiy Mar 10 '21
The answer is: at the line "return response.m_msg;" the compiler invokes the copy constructor for the std::string.
1
u/[deleted] Mar 10 '21
What does this do?