#include <iostream>
#include <type_traits>
#include <vector>
#include <list>
#include <string>
namespace
{
template<typename Type>
constexpr bool is_integer()
{
return std::is_same_v<Type, int> ||
std::is_same_v<Type, unsigned> ||
std::is_same_v<Type, signed> ||
std::is_same_v<Type, short> ||
std::is_same_v<Type, unsigned short> ||
std::is_same_v<Type, signed short> ||
std::is_same_v<Type, long> ||
std::is_same_v<Type, signed long> ||
std::is_same_v<Type, unsigned long> ||
std::is_same_v<Type, long long> ||
std::is_same_v<Type, unsigned long long> ||
std::is_same_v<Type, signed long long>;
}
template<template<class, class> class Container, class Type>
constexpr bool is_allow_container()
{
return std::is_same_v<Container, std::string> ||
(std::is_same_v<Container, std::vector> && is_integer<Type>() ) ||
(std::is_same_v<Container, std::list<Type>> && is_integer<Type>() );
}
} // namespace
class Class{
public:
template<typename Type,
class = typename std::enable_if_t< is_integer<Type>() ||
is_allow_container<Type, typename Type::value_type>() > >
Class(Type&){}
template<typename Type,
class = typename std::enable_if_t< is_integer<Type>() ||
is_allow_container<Type, typename Type::value_type>() > >
Class(Type&&){}
template<typename Type,
class = typename std::enable_if_t< is_integer<Type>() ||
is_allow_container<Type, typename Type::value_type>() > >
Class(const Type&){}
};
int main()
{
std::vector<int> v;
Class a(v);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHlwZV90cmFpdHM+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxsaXN0PgojaW5jbHVkZSA8c3RyaW5nPgoKbmFtZXNwYWNlCnsKCnRlbXBsYXRlPHR5cGVuYW1lIFR5cGU+CmNvbnN0ZXhwciBib29sIGlzX2ludGVnZXIoKQp7CiAgICByZXR1cm4gc3RkOjppc19zYW1lX3Y8VHlwZSwgaW50PiB8fAogICAgICAgICAgICBzdGQ6OmlzX3NhbWVfdjxUeXBlLCB1bnNpZ25lZD4gfHwKICAgICAgICAgICAgc3RkOjppc19zYW1lX3Y8VHlwZSwgc2lnbmVkPiB8fAogICAgICAgIC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cGUsCiAgICAgICAgY2xhc3MgPSB0eXBlbmFtZSBzdGQ6OmVuYWJsZV9pZl90PCBpc19pbnRlZ2VyPFR5cGU+KCkgfHwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlzX2FsbG93X2NvbnRhaW5lcjxUeXBlLCB0eXBlbmFtZSBUeXBlOjp2YWx1ZV90eXBlPigpID4gPgogICAgQ2xhc3MoVHlwZSYpe30KCiAgICB0ZW1wbGF0ZTx0eXBlbmFtZSBUeXBlLAogICAgICAgIGNsYXNzID0gdHlwZW5hbWUgc3RkOjplbmFibGVfaWZfdDwgaXNfaW50ZWdlcjxUeXBlPigpIHx8CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpc19hbGxvd19jb250YWluZXI8VHlwZSwgdHlwZW5hbWUgVHlwZTo6dmFsdWVfdHlwZT4oKSA+ID4KICAgIENsYXNzKFR5cGUmJil7fQoKICAgIHRlbXBsYXRlPHR5cGVuYW1lIFR5cGUsCiAgICAgICAgY2xhc3MgPSB0eXBlbmFtZSBzdGQ6OmVuYWJsZV9pZl90PCBpc19pbnRlZ2VyPFR5cGU+KCkgfHwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlzX2FsbG93X2NvbnRhaW5lcjxUeXBlLCB0eXBlbmFtZSBUeXBlOjp2YWx1ZV90eXBlPigpID4gPgogICAgQ2xhc3MoY29uc3QgVHlwZSYpe30KfTsKCmludCBtYWluKCkKewogICAgc3RkOjp2ZWN0b3I8aW50PiB2OwogICAgQ2xhc3MgYSh2KTsKCiAgICByZXR1cm4gMDsKfQo=
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&&’