fork(15) download
  1. #include <type_traits>
  2.  
  3. namespace detail{
  4. template<int> struct sfinae_true : std::true_type{};
  5. template<class T>
  6. sfinae_true<(T::f(), 0)> check(int);
  7. template<class>
  8. std::false_type check(...);
  9. } // detail::
  10.  
  11. template<class T>
  12. struct has_constexpr_f : decltype(detail::check<T>(0)){};
  13.  
  14. struct trait
  15. {
  16. static int f(){ return 15; }
  17. };
  18.  
  19. struct ctrait
  20. {
  21. static constexpr int f(){ return 20; }
  22. };
  23.  
  24. static_assert(has_constexpr_f<trait>() == false, "trait");
  25. static_assert(has_constexpr_f<ctrait>() == true, "ctrait");
  26.  
  27. int main(){}
  28.  
Success #stdin #stdout 0s 2892KB
stdin
Standard input is empty
stdout
Standard output is empty