Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <type_traits>
- using namespace std;
- template<bool Test, typename T = void>
- using enabled_if = typename enable_if<Test, T>::type;
- template<typename ThisType, typename... Types>
- struct is_belong;
- template<typename ThisType, typename ThatType, typename... Types>
- struct is_belong
- <ThisType,
- ThatType,
- Types...> : is_belong<ThisType, Types...> {};
- template<typename ThisType, typename... Types>
- struct is_belong
- <ThisType,
- ThisType,
- Types...> : true_type {};
- template<typename ThisType>
- struct is_belong<ThisType> : false_type {};
- template<typename ThisType, typename... Types> // ДОБАВЛЕНО:
- constexpr bool is_belonged() {return is_belong<ThisType, Types...>::value;}
- //Identity function which works only
- //for `short`, `int` and `long`:
- template<typename T,
- enabled_if<is_belonged<T, short, int, long>()>... Check> // ИЗМЕНЕНО
- T I(const T& val) {
- return val;
- }
- int main() {
- int n = 100;
- int n1 = I(n);
- assert(n == n1);
- double d = 100;
- //Compilation error - works fine
- double d1 = I(d);
- //assert(d == d1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement