What would be a good implementation of iota_n (missing algorithm from the STL)

前端 未结 3 1042
甜味超标
甜味超标 2020-12-19 02:28

With C++11, the STL has now a std::iota function (see a reference). In contrast to std::fill_n, std::generate_n, there is no std

3条回答
  •  天命终不由人
    2020-12-19 03:21

    A hypothetical iota_n

    std::iota_n(first, count, value)

    can be replaced by a one liner.

    std::generate_n(first, count, [v=value]()mutable{return v++;})

    I prefer this to have a lingering function that is not in the standard. Having said that, I think a std::iota_n should be in the standard.

提交回复
热议问题