Advertisement
frasl

Untitled

Feb 15th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. template<class T>
  2. constexpr auto supportsAPI(T x) -> decltype(x.Method1(), x.Method2(), true_type{}) {
  3.  return {};
  4. }
  5. constexpr auto supportsAPI(...) -> false_type {
  6.  return {};
  7. }
  8.  
  9. template<class T>
  10. auto compute(T x) -> decltype( enable_if_t< supportsAPI(T{}), int>{}) {
  11.  return x.Method();
  12. }
  13.  
  14. template<class T>
  15. auto compute(T x) -> decltype( enable_if_t<!supportsAPI(T{}), int>{}) {
  16.  return 0;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement