I can't get the type of an element. This solution returns a reference to element type.
int arr[] = { 0, 1, 2, 3, 4, 5 };
using arrElemType = decltype(*arr);
vector<arrElemType> vec(std::cbegin(arr), std::cend(arr));
Try the following
using arrElemType = std::remove_reference<decltype( *arr )>::type;
or
typedef std::remove_reference<decltype( *arr )>::type arrElemType;
You need to include header <type_traits>
The standard way in C++11 and above is to use std::remove_all_extents
.
#include <type_traits>
int arr[] = { 0, 1, 2, 3, 4, 5 };
using arrElemType = std::remove_all_extents<decltype(arr)>::type;
vector<arrElemType> vec(std::cbegin(arr), std::cend(arr));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With