Last active
October 26, 2017 13:12
-
-
Save mbianco/f14fe59018a77c04220a5519857d7a1e to your computer and use it in GitHub Desktop.
Trying to get some compiler errors to arise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <type_traits> | |
template <int... Ints> | |
struct basic_int_list {}; | |
template <int... Values> | |
struct strange_int_list {}; | |
template <template <int...> class Container, int... Values> | |
struct working_thing { | |
using type = Container<Values...>; | |
}; | |
template <class Int, template <Int...> class Container, int... Values> | |
struct buggy_thing { | |
using type = Container<Values...>; | |
}; | |
template <class Int, template <Int> class Container> | |
struct buggy_thing<Int, Container> { | |
using type = Container<0>; | |
}; | |
int main(int, const char**) { | |
static_assert(std::is_same< | |
typename working_thing<basic_int_list, 1, 2, 3>::type, | |
basic_int_list<1, 2, 3> | |
>::value, "should work always"); | |
static_assert(std::is_same< | |
typename working_thing<strange_int_list, 1, 2, 3>::type, | |
strange_int_list<1, 2, 3> | |
>::value, "should work always"); | |
static_assert(std::is_same< | |
typename working_thing<strange_int_list>::type, | |
strange_int_list< > | |
>::value, "should work always"); | |
static_assert(std::is_same< | |
typename buggy_thing<int, basic_int_list, 1, 2, 3>::type, | |
basic_int_list<1, 2, 3> | |
>::value, "should always work"); | |
static_assert(std::is_same< | |
typename buggy_thing<int, strange_int_list, 1, 2, 3>::type, | |
strange_int_list<1, 2, 3> | |
>::value, "does not compile on ICC!"); | |
static_assert(std::is_same< | |
typename buggy_thing<int, strange_int_list>::type, | |
strange_int_list<0> | |
>::value, "does not compile on ICC still!"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment