ned14 / status-code

Proposed SG14 status_code for the C++ standard

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

quick status code from enum and T?

hazelnusse opened this issue · comments

Folks in my org have been asking for something similar to quick_status_code_from_enum that can also transport an "arbitrary" T as a payload next to the enum. A common case is a run-time defined string but it could instead be something else, if it makes sense for the caller to do the stringifying instead of the callee.

The approaches I can see are:

  1. follow the pattern demonstrated by quick_status_code_from_enum but add a template parameter to _quick_status_code_from_enum_domain and change value_type to something like a std::pair<Enum, T>
  2. Define another class that implements the necessary bits of the status_code API and contains private quick_status_code_from_enum and a T.
  3. maybe something better?

I'm inclined to believe that 1) is the right approach but would love to hear your thoughts on the matter.

I figured that this would be asked soon.

Can I come back to this after end of June? There is a big work deadline. Currently working crunch, so there is zero time left outside of work.

@ned14 Absolutely, no rush. We want to do it right and there isn't a huge demand for it at the moment so let's continue the discussion when your deadline is over. Thanks again!

I just added some test code there to check if custom payloads is working. It is, it was since the feature was added.

Perhaps what was a little confusing was that the payload handling gets encoded into your custom type. This is in fact identical to how it works in any case i.e. outside quick status codes. If you have any questions, do come back to me. And thanks for waiting.