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<typename recursive_iter_value_t_detail<T>::type> type;
};
template<typename T>
using recursive_iter_value_t = typename recursive_iter_value_t_detail<T>::type;
After trying to compile this code, the only error message 'recursive_iter_value_t_detail': requires clause is incompatible with the declaration popped up and I am not sure what's requires clause is incompatible with the declaration meaning. Is the problem that template struct can't be overloaded like this? Please help me to figure this out.
The expected output of recursive_iter_value_t<std::vector<std::vector<int>>> is int.