Typedef for a pointer to a cv- and/or ref-qualified member function

Viewed 222
struct foo {
    void bar(int&&) && { }
};

template<class T>
using bar_t = void (std::decay_t<T>::*)(int&&) /* add && if T is an rvalue reference */;

int main()
{
    using other_t = void (foo::*)(int&&) &&;
    static_assert(std::is_same<bar_t<foo&&>, other_t>::value, "not the same");

    return 0;
}

I want that

  • bar_t<T> yields void (foo::*)(int&&) if T = foo
  • bar_t<T> yields void (foo::*)(int&&) const if T = foo const
  • bar_t<T> yields void (foo::*)(int&&) & if T = foo&
  • bar_t<T> yields void (foo::*)(int&&) const& if T = foo const&

and so on. How can I achieve that?

1 Answers
Related