fork(1) download
  1. #include <type_traits>
  2.  
  3. template<class Fty>
  4. struct is_ptcmf : std::false_type{};
  5.  
  6. template<class C, class R, class... Args>
  7. struct is_ptcmf<R (C::*)(Args...) const> : std::true_type{};
  8.  
  9. template<class C, class Fty, Fty F>
  10. struct A{
  11. static_assert(std::is_const<C>() == is_ptcmf<Fty>(), "Must pair const with const.");
  12. };
  13.  
  14. struct X{
  15. void foo(){}
  16. void bar() const{}
  17. };
  18.  
  19. template<class... Args>
  20. void swallow(Args&&...){}
  21.  
  22. int main(){
  23. A<X, decltype(&X::foo), &X::foo> a1;
  24. A<X const, decltype(&X::bar), &X::bar> a2;
  25. swallow(a1, a2);
  26.  
  27. //A<X const, decltype(&X::foo), &X::foo> a3; // error: static_assert
  28. //A<X, decltype(&X::bar), &X::bar> a4; // error: static_assert
  29. //swallow(a3, a4)
  30. }
Success #stdin #stdout 0s 2848KB
stdin
Standard input is empty
stdout
Standard output is empty