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

前端 未结 5 1433
抹茶落季
抹茶落季 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:23

    C++11:

    std::vector idxs (n);
    
    std::generate_n (idxs.begin (), n, [] { static int i {1}; return i++; });
    

提交回复
热议问题