I would like to have a function that will take any range/view of a fixed value type.
int main()
{
std::array<std::pair<int, int>, 2> a{...};
std::array<std::pair<int, int>, 3> b{...};
generic_fun(a);
generic_fun(b);
};
Of course I could do
template <std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>,std::pair<int,int>>
auto generic_fun(R range)
{
for(const auto& element : range)
return element.first;
}
but then the visual studio ide doesn't know the type of element
.
I was expecting the ranges library to have some type like
template <typename T>
struct view
{
template <std::ranges::range R>
requires std::same_as<std::ranges::range_value_t<R>, T>
view(R);
T* begin() const;
T* end() const;
};
Which would give me ide support for
auto generic_fun(view<std::pair<int,int>> a)
{
for (const auto& b : a)
return b.first;
}
Why doesn't such a type exist in the ranges library? Is it technically infeasible to define a type that abstracts away all but the value type of ranges/iterators? Or does no-one care about doing this because the only reason is ide support?
I though it would be natural to have a type (templated on a given value type) that wraps a given iterator concept, but std doesn't define any. (If there's something to read on the internet about types that wrap concepts, could you point me there please?)