Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. template<bool Condition, typename T = int>
  2. struct EnableIf_c {};
  3.  
  4. template<typename T>
  5. struct EnableIf_c<true, T>
  6. {
  7.     typedef T type;
  8. };
  9.  
  10. template<int N, typename = void>
  11. struct IsEven
  12. {
  13.     static const bool value = false;
  14. };
  15.  
  16. template<int N>
  17. struct IsEven<N, typename EnableIf_c<(N % 2) == 0>::type>
  18. {
  19.     static const bool value = true;
  20. };
  21.  
  22. int main()
  23. {
  24.     static_assert(!IsEven<3>::value);   // works
  25.     static_assert(IsEven<2>::value);  // fails as long as T = int in first line. When T = void, then it works
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement