I am trying to implement a recursive version std::iter_value_t
with C++20 concept so that the base type T
of nested container like std::vector<std::vector<...std::vector<T>...>>
can be retrieved. The experimental implementation is as below.
template<typename T>
concept is_iterable = requires(T x)
{
*std::begin(x);
std::end(x);
};
template<typename T> requires (!is_iterable<T>)
struct recursive_iter_value_t_detail
{
typedef typename T type;
};
template<typename T> requires (is_iterable<T>)
struct recursive_iter_value_t_detail
{
typedef typename std::iter_value_t<recursive_iter_value_t_detail<T>::type> type;
};
template<typename T>
using recursive_iter_value_t = recursive_iter_value_t_detail<T>::type;
However, I got the error message 'type': use of dependent type name must be prefixed with 'typename'
and I am wondering where the problem is exactly.
The expected output of recursive_iter_value_t<std::vector<std::vector<int>>>
is int
.