Obtaining a & to an error #5
-
Hello, is there any way to get a reference to the error within a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @alexanderlinne, good question. The short version is no, not currently -- but this is by design. The main reason for this is that I didn't want In general, error types are meant to be lightweight; either integer values, What is the particular case you are working with that references would be a better fit? I'm open to suggestions for improvements if this is an important feature. |
Beta Was this translation helpful? Give feedback.
I have been in a similar situations in one of my own codebases with a larger error object; though I solved this through an extra layer of indirection by creating an
error_handle
type that contains either aunique_ptr
orshared_ptr
to the error data. Is something similar to this a possible workaround for the situation you are experiencing?This
result
implementation was designed with the idea thaterror
states are meant to be light-weight. A handle like this makes it easy to returnerror()
and not care for the cost of the copy (which for a handle usingshared_ptr
, would just be a couple pointer copies and an atomic increment).