Skip to content

Provide access to self in weak dispatch? #193

@Shuenhoy

Description

@Shuenhoy

The current example of weak dispatch is just a "not implemented". However, to make a more useful default implementation, it is very common to access self, so that we can implement a weak dispatch with other non-weak dispatches.

I have found this is possible by manually defining the dispatch as

struct dispatch_name : existing_dispatch {
  using existing_dispatch::operator();
  template <class Self, class... Args>
  decltype(auto) operator()(Self&& self, Args&&... args)
      noexcept(noexcept(default_func_name(std::forward<Self>(self), std::forward<Args>(args)...)))
      requires(requires { default_func_name(std::forward<Self>(self), std::forward<Args>(args)...); } and not std::same_as<Self, std::nullptr_t>) {
    return default_func_name(std::forward<Self>(self), std::forward<Args>(args)...);
  }
};

But it might be worth adding a new helper macro for this, what do you think about it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions