fork(7) download
  1. #include <iostream>
  2. #include <type_traits>
  3. using namespace std;
  4.  
  5. template<typename... > struct Voider { using Type = void; };
  6. template<typename... TArgs> using VoidT = typename Voider<TArgs...>::Type;
  7.  
  8. template< class, class = void >
  9. struct hasGetCount : false_type { };
  10.  
  11. template< class T >
  12. struct hasGetCount<T,
  13. VoidT<
  14. decltype(std::declval<int&>() = std::declval<T>().getCount())
  15. >> : std::true_type {};
  16.  
  17. struct TestTrue
  18. {
  19. int getCount() { return 0; }
  20. };
  21.  
  22. struct TestFalse
  23. {
  24. };
  25.  
  26. int main()
  27. {
  28. static_assert(hasGetCount<TestTrue>::value == true, "");
  29. static_assert(hasGetCount<TestFalse>::value == false, "");
  30. }
Success #stdin #stdout 0s 3292KB
stdin
Standard input is empty
stdout
Standard output is empty