fork download
  1. #include <iostream>
  2. #include <type_traits>
  3. #include <vector>
  4. #include <list>
  5. #include <string>
  6.  
  7. namespace
  8. {
  9.  
  10. template<typename Type>
  11. constexpr bool is_integer()
  12. {
  13. return std::is_same_v<Type, int> ||
  14. std::is_same_v<Type, unsigned> ||
  15. std::is_same_v<Type, signed> ||
  16. std::is_same_v<Type, short> ||
  17. std::is_same_v<Type, unsigned short> ||
  18. std::is_same_v<Type, signed short> ||
  19. std::is_same_v<Type, long> ||
  20. std::is_same_v<Type, signed long> ||
  21. std::is_same_v<Type, unsigned long> ||
  22. std::is_same_v<Type, long long> ||
  23. std::is_same_v<Type, unsigned long long> ||
  24. std::is_same_v<Type, signed long long>;
  25. }
  26.  
  27. template<template<class, class> class Container, class Type>
  28. constexpr bool is_allow_container()
  29. {
  30. return std::is_same_v<Container, std::string> ||
  31. (std::is_same_v<Container, std::vector> && is_integer<Type>() ) ||
  32. (std::is_same_v<Container, std::list<Type>> && is_integer<Type>() );
  33. }
  34.  
  35. } // namespace
  36.  
  37. class Class{
  38. public:
  39. template<typename Type,
  40. class = typename std::enable_if_t< is_integer<Type>() ||
  41. is_allow_container<Type, typename Type::value_type>() > >
  42. Class(Type&){}
  43.  
  44. template<typename Type,
  45. class = typename std::enable_if_t< is_integer<Type>() ||
  46. is_allow_container<Type, typename Type::value_type>() > >
  47. Class(Type&&){}
  48.  
  49. template<typename Type,
  50. class = typename std::enable_if_t< is_integer<Type>() ||
  51. is_allow_container<Type, typename Type::value_type>() > >
  52. Class(const Type&){}
  53. };
  54.  
  55. int main()
  56. {
  57. std::vector<int> v;
  58. Class a(v);
  59.  
  60. return 0;
  61. }
  62.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘constexpr bool {anonymous}::is_integer()’:
prog.cpp:13:17: error: ‘is_same_v’ is not a member of ‘std’
     return std::is_same_v<Type, int> ||
                 ^~~~~~~~~
prog.cpp:13:17: note: suggested alternative: ‘is_same’
     return std::is_same_v<Type, int> ||
                 ^~~~~~~~~
                 is_same
prog.cpp:13:31: error: expected primary-expression before ‘,’ token
     return std::is_same_v<Type, int> ||
                               ^
prog.cpp:13:33: error: expected primary-expression before ‘int’
     return std::is_same_v<Type, int> ||
                                 ^~~
prog.cpp:13:32: error: expected ‘;’ before ‘int’
     return std::is_same_v<Type, int> ||
                                ^~~~
                                ;
prog.cpp:13:36: error: expected unqualified-id before ‘>’ token
     return std::is_same_v<Type, int> ||
                                    ^
prog.cpp: In function ‘constexpr bool {anonymous}::is_allow_container()’:
prog.cpp:30:17: error: ‘is_same_v’ is not a member of ‘std’
     return std::is_same_v<Container, std::string> ||
                 ^~~~~~~~~
prog.cpp:30:17: note: suggested alternative: ‘is_same’
     return std::is_same_v<Container, std::string> ||
                 ^~~~~~~~~
                 is_same
prog.cpp:30:36: error: missing template arguments before ‘,’ token
     return std::is_same_v<Container, std::string> ||
                                    ^
prog.cpp:30:49: error: expected primary-expression before ‘>’ token
     return std::is_same_v<Container, std::string> ||
                                                 ^
prog.cpp:30:51: error: expected primary-expression before ‘||’ token
     return std::is_same_v<Container, std::string> ||
                                                   ^~
prog.cpp:31:18: error: ‘is_same_v’ is not a member of ‘std’
            (std::is_same_v<Container, std::vector> && is_integer<Type>() ) ||
                  ^~~~~~~~~
prog.cpp:31:18: note: suggested alternative: ‘is_same’
            (std::is_same_v<Container, std::vector> && is_integer<Type>() ) ||
                  ^~~~~~~~~
                  is_same
prog.cpp:31:37: error: missing template arguments before ‘,’ token
            (std::is_same_v<Container, std::vector> && is_integer<Type>() ) ||
                                     ^
prog.cpp:31:50: error: missing template arguments before ‘>’ token
            (std::is_same_v<Container, std::vector> && is_integer<Type>() ) ||
                                                  ^
prog.cpp:31:70: error: expected primary-expression before ‘>’ token
            (std::is_same_v<Container, std::vector> && is_integer<Type>() ) ||
                                                                      ^
prog.cpp:31:72: error: expected primary-expression before ‘)’ token
            (std::is_same_v<Container, std::vector> && is_integer<Type>() ) ||
                                                                        ^
prog.cpp:32:18: error: ‘is_same_v’ is not a member of ‘std’
            (std::is_same_v<Container, std::list<Type>> && is_integer<Type>() );
                  ^~~~~~~~~
prog.cpp:32:18: note: suggested alternative: ‘is_same’
            (std::is_same_v<Container, std::list<Type>> && is_integer<Type>() );
                  ^~~~~~~~~
                  is_same
prog.cpp:32:37: error: missing template arguments before ‘,’ token
            (std::is_same_v<Container, std::list<Type>> && is_integer<Type>() );
                                     ^
prog.cpp:32:53: error: expected primary-expression before ‘>’ token
            (std::is_same_v<Container, std::list<Type>> && is_integer<Type>() );
                                                     ^~
prog.cpp:32:74: error: expected primary-expression before ‘>’ token
            (std::is_same_v<Container, std::list<Type>> && is_integer<Type>() );
                                                                          ^
prog.cpp:32:76: error: expected primary-expression before ‘)’ token
            (std::is_same_v<Container, std::list<Type>> && is_integer<Type>() );
                                                                            ^
prog.cpp: In function ‘int main()’:
prog.cpp:58:14: error: no matching function for call to ‘Class::Class(std::vector<int>&)’
     Class a(v);
              ^
prog.cpp:52:5: note: candidate: ‘template<class Type, class> Class::Class(const Type&)’
     Class(const Type&){}
     ^~~~~
prog.cpp:52:5: note:   template argument deduction/substitution failed:
prog.cpp:41:95: error: no matching function for call to ‘is_allow_container<std::vector<int, std::allocator<int> >, std::vector<int>::value_type>()’
                                            is_allow_container<Type, typename Type::value_type>() > >
                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
prog.cpp:28:16: note: candidate: ‘template<template<class, class> class Container, class Type> constexpr bool {anonymous}::is_allow_container()’
 constexpr bool is_allow_container()
                ^~~~~~~~~~~~~~~~~~
prog.cpp:28:16: note:   template argument deduction/substitution failed:
prog.cpp:47:5: note: candidate: ‘template<class Type, class> Class::Class(Type&&)’
     Class(Type&&){}
     ^~~~~
prog.cpp:47:5: note:   template argument deduction/substitution failed:
prog.cpp:41:44: error: ‘std::vector<int>&’ is not a class, struct, or union type
                                            is_allow_container<Type, typename Type::value_type>() > >
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:42:5: note: candidate: ‘template<class Type, class> Class::Class(Type&)’
     Class(Type&){}
     ^~~~~
prog.cpp:42:5: note:   template argument deduction/substitution failed:
prog.cpp:41:95: error: no matching function for call to ‘is_allow_container<std::vector<int, std::allocator<int> >, std::vector<int>::value_type>()’
                                            is_allow_container<Type, typename Type::value_type>() > >
                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
prog.cpp:28:16: note: candidate: ‘template<template<class, class> class Container, class Type> constexpr bool {anonymous}::is_allow_container()’
 constexpr bool is_allow_container()
                ^~~~~~~~~~~~~~~~~~
prog.cpp:28:16: note:   template argument deduction/substitution failed:
prog.cpp:37:7: note: candidate: ‘constexpr Class::Class(const Class&)’
 class Class{
       ^~~~~
prog.cpp:37:7: note:   no known conversion for argument 1 from ‘std::vector<int>’ to ‘const Class&’
prog.cpp:37:7: note: candidate: ‘constexpr Class::Class(Class&&)’
prog.cpp:37:7: note:   no known conversion for argument 1 from ‘std::vector<int>’ to ‘Class&&’
stdout
Standard output is empty