Initialization of std::vector with a list of consecutive unsigned integers

前端 未结 5 1438
抹茶落季
抹茶落季 2020-12-16 03:45

I want to use a special method to initialize a std::vector which is described in a C++ book I use as a reference (the German book \'Der C++

5条回答
  •  悲&欢浪女
    2020-12-16 04:08

    Reread the paragraphs near there describing what each of the parameters are. Specifically, it should mention that i and j are not values, but iterators. This constructor is very commonly used to make copies of other types of containers. If you want to get a sequence of values, the Boost library provides a counting iterator, that does exactly what you want.

    std::vector numbers(
         boost::counting_iterator(0U),
         boost::counting_iterator(10U));
    

提交回复
热议问题