Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<bool Condition, typename T = int>
- struct EnableIf_c {};
- template<typename T>
- struct EnableIf_c<true, T>
- {
- typedef T type;
- };
- template<int N, typename = void>
- struct IsEven
- {
- static const bool value = false;
- };
- template<int N>
- struct IsEven<N, typename EnableIf_c<(N % 2) == 0>::type>
- {
- static const bool value = true;
- };
- int main()
- {
- static_assert(!IsEven<3>::value); // works
- static_assert(IsEven<2>::value); // fails as long as T = int in first line. When T = void, then it works
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement