Removing the void specializations for std::future and std::promise

Viewed 716

With regards to the paper which describes removing the void specializations for std::future and std::promise P0241R0. This may be a stupid question but the proposed solution is to remove the void specialization entirely, but then what are people expected to do when they want to instantiate a std::future<void>object?

3 Answers

Having tinkered with implementing the TS, it seems possible to avoid specializing for void if the implementation does some clever things with enable_if, e.g.

template <class R>
R future<R>::get()
{
  return shared().get();
}

template <class R>
class shared_state {
  ...
  R get()
  {
    wait();
    if constexpr (!std::is_same_v<V, void>) {
      return *_value;
    }
  }

  template <typename V = value_t, std::enable_if_t<!std::is_same_v<V, void>, V>* = nullptr>
  void set_value(const V& value)
  {
    ...
  }

  template <typename V = value_t, std::enable_if_t<std::is_same_v<V, void>, V>* = nullptr>
  void set_value()
  {
    ...
  }
}

Related