Hook outcome

The final step is to add ADL discovered event hooks for the very specific case of when our localised outcome is copy or move constructed from our localised result. There isn’t really much to say about these, just be careful to mark them noexcept or not based on whether the types T, EC or EP could throw during copy or move construction. As poke_exception() creates a std::string and appends to it, it could indeed throw an exception and thus with the noexcept hooks below, the process would be terminated.


namespace error_code_extended
{
  // Specialise the outcome copy and move conversion hook for when our localised result
  // is used as the source for copy construction our localised outcome
  template <class T, class U> inline void hook_outcome_copy_construction(outcome<T> *res, const result<U> & /*unused*/) noexcept
  {
    // when copy constructing from a result<T>, poke in an exception
    poke_exception(res);
  }
  template <class T, class U> inline void hook_outcome_move_construction(outcome<T> *res, result<U> && /*unused*/) noexcept
  {
    // when move constructing from a result<T>, poke in an exception
    poke_exception(res);
  }
}
View this code on Github