I'm new to variadic templates and for the sake of learning consider the following function
template <typename T, typename... args>
T* make_arr(args... arg) {
// Code to check if passed args are of the same type
T* arr = new T[sizeof...(arg)]{ arg... };
return arr;
}
I have two questions:
- I want the function to be templated and I want the passed arguments to be of the same type so the question: is it possible to check if passed arguments are of the same type ?
- Is it possible to deduce the type of the array pointer by deducing the type of
args...
, I mean without using<typename T>
? ... I used decltype(arg) but it didnt work ...
Note: please edit the title question if it is not appropriate ... thanks