Facing issue std::ranges::to I am executing the below example from https://en.cppreference.com/w/cpp/ranges/to
#include <algorithm>
#include <concepts>
#include <iostream>
#include <ranges>
#include <vector>
int main()
{
auto vec = std::views::iota(1, 5)
| std::views::transform([](auto const v){ return v * 2; })
| std::ranges::to<std::vector>();
static_assert(std::same_as<decltype(vec), std::vector<int>>);
std::ranges::for_each(vec, [](auto const v){ std::cout << v << ' '; });
}
But getting a error
main.cpp: In function 'int main()':
main.cpp:11:29: error: 'to' is not a member of 'std::ranges'
11 | | std::ranges::to<std::vector>();
| ^~
main.cpp:11:43: error: missing template arguments before '>' token
11 | | std::ranges::to<std::vector>();
| ^
main.cpp:11:45: error: expected primary-expression before ')' token
11 | | std::ranges::to<std::vector>();
| ^
main.cpp:13:24: error: template argument 1 is invalid
13 | static_assert(std::same_as<decltype(vec), std::vector<int>>);
https://coliru.stacked-crooked.com/view?id=8fdd3554af82ef24
I am using the compiler C++23
ranges::to
: godbolt.org/z/6fYx87v4K – Bedplate