0

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.

JimmyHu
  • 403
  • 1
  • 8
  • 20
  • What do you mean it doesn't work? Does it fail to compile? Then show the error. If it compiles but gives the wrong type, state what type that is. – cigien Dec 09 '20 at 03:07
  • @cigien Thank you for the comment, the compile error I got is `'type': use of dependent type name must be prefixed with 'typename'`. However, I have no idea where the `typename` keyword need to be placed. – JimmyHu Dec 09 '20 at 03:09
  • Please add all relevant information to the question, not as a comment. – cigien Dec 09 '20 at 03:11

0 Answers0