fork download
  1. #include <type_traits>
  2. #include <utility>
  3.  
  4. template <typename T> struct val : T {};
  5.  
  6. // Dependent true type for sfinae purposes
  7. template <typename>
  8. struct sfinae_true : std::true_type {};
  9.  
  10. template <typename T, typename... Args>
  11. struct is_list_initializable {
  12. private:
  13. template <typename T1, typename... Args1>
  14. static sfinae_true<decltype(T1 { std::declval<Args1>()... })> test(int);
  15. template <typename, typename...>
  16. static std::false_type test(...);
  17.  
  18. public:
  19. enum { value = val<decltype(test<T, Args...>(0))>::value };
  20. };
  21.  
  22. #include <vector>
  23.  
  24. struct aggregate { int x; int y; };
  25.  
  26. #define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
  27.  
  28. STATIC_ASSERT(is_list_initializable<std::vector<int>, int, int>::value);
  29. STATIC_ASSERT(!is_list_initializable<std::vector<int>, int, double>::value);
  30. STATIC_ASSERT(is_list_initializable<aggregate, int, int>::value);
  31.  
  32. int main() {}
  33.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'is_list_initializable<std::vector<int>, int, double>':
prog.cpp:29:1:   instantiated from here
prog.cpp:14:67: internal compiler error: in cp_tree_equal, at cp/tree.c:2215
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
stdout
Standard output is empty