How to fill a vector with non-trivial initial values?

后端 未结 6 1482
一向
一向 2021-02-05 12:38

I know how to fill an std::vector with non-trivial initial values, e.g. sequence numbers:

void IndexArray( unsigned int length, std::vector&a         


        
6条回答
  •  不思量自难忘°
    2021-02-05 13:30

    If you're using SGI STL (or a derivative, such as STLPort), you can use iota. :-)

    void IndexArray(unsigned int length, vector& v)
    {
        vector(length).swap(v);
        iota(v.begin(), v.end(), 0);
    }
    

提交回复
热议问题