Re: [boost] Proposed SG14 <system_error2> ready for feedback

On 02/28/18 23:10, Niall Douglas via Boost wrote:
7. `std::error_code` enforced its value to always be an `int`. This is problematic for coding systems which might use a `long` and implement coding namespaces within the extended number of bits, or for end users wishing to combine a code with a `void *` in order to transmit payload or additional context. As a result, `status_code` is templated to its domain, and the domain sets its type. A type erased edition of `status_code<D>` is available as `status_code<void>`, this is for obvious reasons non-copyable, non-movable and non-destructible.
A more useful type erased edition is `status_code
` which is available if `D::value_type` is trivially copyable, `T` is an integral type, and `sizeof(T) >= sizeof(D::value_type)`. This lets you use `status_code ` in all your public interfaces without restrictions. As a pointer to the original category is retained, and trivially copyable types may be legally copied by `memcpy()`, type erased status codes work exactly as normal, except that publicly it does not advertise its type.
While I do see the need for providing extensions, I am not sure if status_code<void> is useful given all its "non-" characteristics. Can you elaborate on its use-cases? I propose that the customizable status_code<D> is renamed to basic_status_code<D>. In keeping with the pre-established practices of std::error_code using int, I furthermore suggest that status_code becomes a non-templated alias for basic_status_code<int>.

A more useful type erased edition is `status_code
` which is available if `D::value_type` is trivially copyable, `T` is an integral type, and `sizeof(T) >= sizeof(D::value_type)`. This lets you use `status_code ` in all your public interfaces without restrictions. As a pointer to the original category is retained, and trivially copyable types may be legally copied by `memcpy()`, type erased status codes work exactly as normal, except that publicly it does not advertise its type. While I do see the need for providing extensions, I am not sure if status_code<void> is useful given all its "non-" characteristics. Can you elaborate on its use-cases?
`const status_code<void> &`
I propose that the customizable status_code<D> is renamed to basic_status_code<D>.
Maybe. I think customisable is the wrong adjective though. It's simply the type-aware edition, often in practice the "type restored" edition.
In keeping with the pre-established practices of std::error_code using int, I furthermore suggest that status_code becomes a non-templated alias for basic_status_code<int>.
I see active harm in doing that. status_code is type safe in a way error_code never was. So, generic_code has a value type of enum class errc for example. You cannot construct a generic_code with anything other than a errc. That's a big gain. Similarly, a com_code has a value type of HRESULT. It too cannot be constructed from anything other than a HRESULT. Niall -- ned Productions Limited Consulting http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/

I don't claim to understand all the implementation details, so sorry if this is dumb question: What happened to the idea to encode failure or success in a single bit in the status_code_domain pointer, thus making the check if an operation succeeded trivial even in the type-erased case? Best Mike

On 03/03/2018 21:11, mike via Boost wrote:
I don't claim to understand all the implementation details, so sorry if this is dumb question:
What happened to the idea to encode failure or success in a single bit in the status_code_domain pointer, thus making the check if an operation succeeded trivial even in the type-erased case?
That was a potential workaround for Boost.System to not break existing code.
A complete rebuild like

-----Original Message----- From: On Behalf Of Niall Douglas via Boost Sent: Saturday, March 3, 2018 11:27 PM
I don't claim to understand all the implementation details, so sorry if this is dumb question:
What happened to the idea to encode failure or success in a single bit in
On 03/03/2018 21:11, mike via Boost wrote: the status_code_domain pointer, thus making the check if an operation succeeded trivial even in the type-erased case?
That was a potential workaround for Boost.System to not break existing code.
A complete rebuild like
doesn't need such hacks. It has a formal empty state for those users who won't risk the cost of a virtual function call. For everybody else, it costs one virtual function call at worst, usually not even that as the compiler will have speculatively inlined the implementation and/or the linker will have implemented the 'final' modifier.
It might not be necessary, but wouldn't it be a worthwhile optimization regardless? Even in the generic case it would work without any cross-module analysis and should generally make the compiler's task easier. It would also make the checks for failure or success constexpr (not sure if that is typically relevant). Or would it imply problematic tradeoffs?
Niall
Mike

A complete rebuild like
doesn't need such hacks. It has a formal empty state for those users who won't risk the cost of a virtual function call. It might not be necessary, but wouldn't it be a worthwhile optimization regardless?
As I mentioned, it has a formal empty state. No further optimisation is needed. It is as efficient as is possible.
Even in the generic case it would work without any cross-module analysis and should generally make the compiler's task easier. It would also make the checks for failure or success constexpr (not sure if that is typically relevant). Or would it imply problematic tradeoffs?
Unlike with
participants (3)
-
Bjorn Reese
-
mike.dev@gmx.de
-
Niall Douglas