Currently only MSVC supports the nifty helper ranges::to
, so I am unable to validate this in another compiler. Basically I have a type alias for a STL container and as soon as I attempt to pass it to ranges::to
, compilation fails. So is this a valid usage? Why does the second (commented-out) example below not compile?
#include <ranges>
#include <vector>
#include <iostream>
template <typename T>
using Vec = std::vector<T>;
int main(int argc, char* argv[]) {
auto vec = std::views::iota(1, 10) | std::ranges::to<std::vector>();
//auto vec = std::views::iota(1, 10) | std::ranges::to<Vec>(); // C2440: cannot convert from 'void' to 'std::vector'.
for (auto& v : vec)
std::cout << v << ", ";
std::cout << std::endl;
}
std::vector
has more than 1 template parameter. The aliasVec
should betemplate <typename ...Ts> using Vec = std::vector<Ts...>;
and that should work. – Zambiastd::allocator<T>
. So I suspected this should also work:using Vec = std::vector<T, std::allocator<T>>;
and also tried this earlier. However, it doesn't. Doesranges::to
need to pass the allocator? – Silvanus