C++ Logo

std-proposals

Advanced search

[std-proposals] CV qualifiers and L-or-R-value as template parameters

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Wed, 2 Apr 2025 12:32:12 +0000
I wrote code last year as follows when I wanted to 'devirtualise' a
member function pointer:

  /* ============ The next 14 lines are to get the 'Class' from R
'(Class:*)(Params...)' */
  template<typename Pmf> struct pmf_class;
  template<bool ex,typename R,class C,typename...P>struct
pmf_class<R(C::*)(P...) noexcept(ex)>{using t=C;};
  template<bool ex,typename R,class C,typename...P>struct
pmf_class<R(C::*)(P...)const noexcept(ex)>{using t=C;};
  template<bool ex,typename R,class C,typename...P>struct
pmf_class<R(C::*)(P...)volatile noexcept(ex)>{using t=C;};
  template<bool ex,typename R,class C,typename...P>struct
pmf_class<R(C::*)(P...)const volatile noexcept(ex)>{using t=C;};
  template<bool ex,typename R,class C,typename...P>struct
pmf_class<R(C::*)(P...) &noexcept(ex)>{using t=C;};
  template<bool ex,typename R,class C,typename...P>struct
pmf_class<R(C::*)(P...)const &noexcept(ex)>{using t=C;};
  template<bool ex,typename R,class C,typename...P>struct
pmf_class<R(C::*)(P...)volatile &noexcept(ex)>{using t=C;};
  template<bool ex,typename R,class C,typename...P>struct
pmf_class<R(C::*)(P...)const volatile &noexcept(ex)>{using t=C;};
  template<bool ex,typename R,class C,typename...P>struct
pmf_class<R(C::*)(P...) &&noexcept(ex)>{using t=C;};
  template<bool ex,typename R,class C,typename...P>struct
pmf_class<R(C::*)(P...)const &&noexcept(ex)>{using t=C;};
  template<bool ex,typename R,class C,typename...P>struct
pmf_class<R(C::*)(P...)volatile &&noexcept(ex)>{using t=C;};
  template<bool ex,typename R,class C,typename...P>struct
pmf_class<R(C::*)(P...)const volatile&&noexcept(ex)>{using t=C;};
  template<typename Pmf> using pmf_class_t = pmf_class<Pmf>::t;
  /* ===================================================================================
*/

And similarly if you look on the "cppreference.com" website for
"std::move_only_function", you'll see:

template< class R, class... Args >
class move_only_function<R(Args...)>;
template< class R, class... Args >
class move_only_function<R(Args...) noexcept>;
template< class R, class... Args >
class move_only_function<R(Args...) &>;
template< class R, class... Args >
class move_only_function<R(Args...) & noexcept>;
template< class R, class... Args >
class move_only_function<R(Args...) &&>;
template< class R, class... Args >
class move_only_function<R(Args...) && noexcept>;
template< class R, class... Args >
class move_only_function<R(Args...) const>;
template< class R, class... Args >
class move_only_function<R(Args...) const noexcept>;
template< class R, class... Args >
class move_only_function<R(Args...) const &>;
template< class R, class... Args >
class move_only_function<R(Args...) const & noexcept>;
template< class R, class... Args >
class move_only_function<R(Args...) const &&>;
template< class R, class... Args >
class move_only_function<R(Args...) const && noexcept>;

Is there some way that we can trim this down a bit? Perhaps, could
cv-qualifiers and R-or-L-value-ness be a part of the template
parameters? Maybe all those lines could be reduced to just one:

template< cvquals, R_or_L, bool noexcept_bool, class R, class... Args >
class move_only_function<R(Args...) cvquals R_or_L noexcept(noexcept_bool) >

Received on 2025-04-02 12:32:29