ranges::iota
ranges::iota (증가 수열 채우기)
범위를 value부터 1씩 증가하는 값들로 채우는 ranges 버전 알고리즘이에요. <numeric> 헤더, C++23부터.
출처: cppreference
본문
std::ranges::iota는 범위의 각 요소에 증가하는 값을 대입해요.
namespace std::ranges {
template< std::input_or_output_iterator O, std::sentinel_for<O> S,
std::weakly_incrementable T >
requires std::indirectly_writable<O, const T&>
constexpr iota_result<O, T> iota( O first, S last, T value );
}
- 반환 타입
iota_result{in, value}. - 채워지는 값은
value, value+1, value+2, .... in은 마지막에 채운 요소 다음 반복자,value는 마지막으로 생성된 값이에요.
std::vector<int> v(5);
std::ranges::iota(v, 1); // v == {1,2,3,4,5}
std::iota의 ranges 버전이에요. 증가 수열을 채울 때 쓰고, 반환값으로 "얼마까지 생성했는지"도 알 수 있어요.